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

时间:2016-01-12 08:01:11

标签: json vb.net json.net

好的,我知道如何使用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

1 个答案:

答案 0 :(得分:0)

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