gpt4 book ai didi

json.net - 无法将 Newtonsoft.Json.Linq.JProperty 转换为 Newtonsoft.Json.Linq.JToken

转载 作者:行者123 更新时间:2023-12-04 05:25:56 26 4
gpt4 key购买 nike

我正在尝试建立 Mike Jansen 的 JIRA REST Client ,我正在尝试提取 JIRA 版本信息。我是 JSON 的新手,所以我不确定这只是格式问题还是什么。

调试时,我有以下标记:

{[
{
"self": "https://<company>.atlassian.net/rest/api/2/version/10101",
"id": "10101",
"name": "2012.3",
"archived": false,
"released": false,
"releaseDate": "2012-10-08"
},
{
"self": "https://<company>.atlassian.net/rest/api/2/version/10200",
"id": "10200",
"name": "2012.4",
"archived": false,
"released": false
}
]}

和下面的代码行

token.Children().Values<T>()

抛出以下错误

Cannot cast Newtonsoft.Json.Linq.JProperty to Newtonsoft.Json.Linq.JToken

尝试将两个版本标记转换为相应的 JiraVersion 类时:

using System;
namespace JiraRestClient
{
public class JiraVersion : JiraObjectBase, IJiraVersion
{
public JiraVersion(IJiraRestResponse jiraResponse) : base(jiraResponse) { }
public string Id { get { return Get<string>("Id", "id"); } }
public string Name { get { return Get<string>("Name", "name"); } }
}
}

有人可以帮帮我吗?

最佳答案

熟悉 JSON 的人可能很快就注意到,这实际上是格式问题(包含数组的额外大括号)。就像我说的,我是 JSON 的新手,但我研究的最终结果是 JsonWrapper.TryGetPath(...) 方法尝试遍历 JObject 树,并且在检索的是数组时不会生成格式正确的 JSON .

我的解决方案是通过从解决方案中删除 JSON.Net 并仅依赖于 RestSharp(只是因为它使发出请求变得如此容易)和 System.Web.Script.Serialization.JavaScriptSerializer().Deserialize( response.Content) 方法。

关于json.net - 无法将 Newtonsoft.Json.Linq.JProperty 转换为 Newtonsoft.Json.Linq.JToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13202953/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com