我有這個 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
.
uj5u.com熱心網友回復:
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)
但是一旦決議了物件,還需要決議陣列嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/473625.html