ASP.NET 将 JSON 文件的一部分转换为 JArray
ASP.NET convert part of JSON file to JArray
我有这个 JSON,我正在尝试使用 Newtonsoft 解析并转换为数组:
{
"generatedAt": "2022-01-01 02:03:25",
"myitems": [
{
"id": "1795089",
"location": {
"name": "Myplace",
"countryCode": "DE"
},
}
,
{
"id": "1795070",
"location": {
"name": "Roseplace",
"countryCode": "US"
},
}
],
"count": 2
}
我尝试了什么:
Dim jsonArray As Newtonsoft.Json.Linq.JArray
jsonArray = JArray.Parse(json)
但这没有找到 myitems
数组。
然后我尝试了:
Dim obj As JObject = JObject.Parse(json)
Dim result As JObject = DirectCast(obj("myitems"), JObject)
但我不知道这是否是推荐的方法或如何将该对象转换为 JArray
。
jarray.parse 需要数组源...但是
Dim jstring as string = "{""generatedAt"": ""2022-01-01 02:03:25"",""myitems"": [{""id"": ""1795089"",""location"":{""name"":""Myplace"",""countryCode"":""DE""},},{""id"":""1795070"",""location"": {""name"": ""Roseplace"",""countryCode"": ""US""},}],""count"": 2}"
Dim jo = Newtonsoft.Json.Linq.JObject.Parse(jstring)
Dim ja = Newtonsoft.Json.Linq.JArray.Parse(jo("myitems").toString)
但是一旦解析了对象,还需要解析数组吗?
我有这个 JSON,我正在尝试使用 Newtonsoft 解析并转换为数组:
{
"generatedAt": "2022-01-01 02:03:25",
"myitems": [
{
"id": "1795089",
"location": {
"name": "Myplace",
"countryCode": "DE"
},
}
,
{
"id": "1795070",
"location": {
"name": "Roseplace",
"countryCode": "US"
},
}
],
"count": 2
}
我尝试了什么:
Dim jsonArray As Newtonsoft.Json.Linq.JArray
jsonArray = JArray.Parse(json)
但这没有找到 myitems
数组。
然后我尝试了:
Dim obj As JObject = JObject.Parse(json)
Dim result As JObject = DirectCast(obj("myitems"), JObject)
但我不知道这是否是推荐的方法或如何将该对象转换为 JArray
。
jarray.parse 需要数组源...但是
Dim jstring as string = "{""generatedAt"": ""2022-01-01 02:03:25"",""myitems"": [{""id"": ""1795089"",""location"":{""name"":""Myplace"",""countryCode"":""DE""},},{""id"":""1795070"",""location"": {""name"": ""Roseplace"",""countryCode"": ""US""},}],""count"": 2}"
Dim jo = Newtonsoft.Json.Linq.JObject.Parse(jstring)
Dim ja = Newtonsoft.Json.Linq.JArray.Parse(jo("myitems").toString)
但是一旦解析了对象,还需要解析数组吗?