循环解析json对象的项和访问属性



好的,我知道如何使用newtonsoft进行解析。但我不知道如何才能获得解析字符串中密钥的每个值

这是json编码的字符串

{"result":[{"orderid":"94","imei":"clipper"},{"orderid":"93","item":"shoes"},{"orderid":"92","item":"bag"},{"orderid":"91","item":"shirt"}]} 
Dim xreadingJson = Newtonsoft.Json.Linq.JObject.Parse(htmlcode)
Dim resultorder As String = xreadingJson.Item("result").ToString

则结果顺序为

[
{
"orderid": "94",
"item": "clipper"
},
{
"orderid": "93",
"item": "shoes"
 },
 {
"orderid": "92",
"item": "shoes"
  },
 {
"orderid": "91",
"item": "bag"
  }
 ]

在循环时,如何获取orderid和item的值。谢谢

更新:我用这个代码解决了这个问题

        Dim o As JObject = JObject.Parse(htmlcode)
        Dim results As List(Of JToken) = o.Children().ToList
        For Each item As JProperty In results
            item.CreateReader()
            'MsgBox(item.Value)
            If item.Value.Type = JTokenType.Array Then
                For Each subitem As JObject In item.Values
                    MsgBox(subitem("orderid"))
                    MsgBox(subitem("item"))
                Next
            End If
        Next

我相信Newtonsoft的JObject有一个JObject.GetValue("property_name")方法

相关内容

  • 没有找到相关文章

最新更新