我有以下 Json,我希望在 vb.net 中循环并提取问题和结果。我尝试使用 Newtonsoft.json,但尽管 JSONlint 验证了 Json,但我得到了错误。实现这一目标的正确方法是什么?
{
"Vehicle_Check": [
19,
{
"question": "Brakes",
"result": "OK",
"Fault": ""
},
{
"question": "Water Levels",
"result": "OK",
"Fault": ""
},
{
"question": "Horn",
"result": "OK",
"Fault": ""
},
{
"question": "Washers",
"result": "OK",
"Fault": ""
},
{
"question": "Wipers",
"result": "OK",
"Fault": ""
},
{
"question": "Indicators",
"result": "OK",
"Fault": ""
},
{
"question": "Reflectors",
"result": "OK",
"Fault": ""
},
{
"question": "Oil Levels",
"result": "OK",
"Fault": ""
},
{
"question": "Lights",
"result": "OK",
"Fault": ""
},
{
"question": "Mirrors",
"result": "OK",
"Fault": ""
},
{
"question": "Steering",
"result": "OK",
"Fault": ""
},
{
"question": "Tyres Wheels",
"result": "OK",
"Fault": ""
},
{
"question": "Battery",
"result": "OK",
"Fault": ""
},
{
"question": "Fuel or Oil Leaks",
"result": "OK",
"Fault": ""
},
{
"question": "Other",
"result": "OK",
"Fault": ""
}
]
}
我用来解析 Json 的代码是:
Dim o As JObject = JObject.Parse(VCItem.Check)
Dim results As List(Of JToken) = o.Children().ToList
For Each item As JProperty In results
item.CreateReader()
Select Case item.Name
'process data here
End Select
Next
这仅返回最后一个元素:
{[
19,
{
"question": "Other",
"result": "OK",
"Fault": ""
}
]}