Newtonssoft Json将Json反序列化为自定义JObject
发布时间:2022-06-19 09:38:42 234
相关标签:
我从API得到了这个结构。
[
{
"Id": 611932,
"ProjectId": 6079,
"Title": "Issue1"
"Viewpoints": [
{
"Id": 885758,
"IssueId": 611932,
"Pinpoint": {
"Position": {
"X": -32.452857971191406,
"Y": -14.971426010131836,
"Z": 9.1110143661499023
}
}
},
{
"Id": 885764,
"IssueId": 611932,
"Pinpoint": {
"Position": {
"X": -21.042057037353516,
"Y": -21.742080688476563,
"Z": 7.72857141494751
}
}
}
]
},
{
"Id": 611931,
"ProjectId": 6079,
"Title": "Issue2",
"Viewpoints": [
{
"Id": 885757,
"IssueId": 611931
},
{
"Id": 885762,
"IssueId": 611931,
"Pinpoint": {
"Position": {
"X": -29.135581970214844,
"Y": -14.971452713012695,
"Z": 7.0672616958618164
}
}
}
]
},
{
"Id": 611930,
"ProjectId": 6079,
"Title": "Issue3",
"Viewpoints": [
{
"Id": 885756,
"IssueId": 611930,
}
]
}
]
我希望能够构建一个包含所有;精确定位;“从全部”;“视点”;以对象的形式生成的结构如下所示(它不必位于数组中,也可以作为新对象包含):
[
{
"Id": 885758,
"IssueId": 611932,
"Pinpoint": {
"Position": {
"X": -32.452857971191406,
"Y": -14.971426010131836,
"Z": 9.1110143661499023
}
}
},
{
"Id": 885764,
"IssueId": 611932,
"Pinpoint": {
"Position": {
"X": -21.042057037353516,
"Y": -21.742080688476563,
"Z": 7.72857141494751
}
}
},
{
"Id": 885762,
"IssueId": 611931,
"Pinpoint": {
"Position": {
"X": -29.135581970214844,
"Y": -14.971452713012695,
"Z": 7.0672616958618164
}
}
}
]
请注意,我没有包含来自 Issue3 的“Viewpoint”数组和来自 issue2 的“Viewpoint”数组的一部分,因为它们不包含“Pinpoint”......
关于如何实现这一目标的任何想法?到目前为止,我已经尝试将每个“位置”对象添加到列表中,仅用于测试目的:
var jArray = JsonConvert.DeserializeObject<dynamic>(response.Content);
List<JToken> results = new List<JToken>();
foreach (JObject jObject in jArray)
{
results.Add(new JObject(jObject["Viewpoints"].Children()["Pinpoint"]["Position"]));
}
但是我收到此错误:
无法将 Newtonsoft.Json.Linq.JObject 添加到 Newtonsoft.Json.Linq.JObject。
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报