[英]VB.NET - convert JSON data into array
I have a JSON result that I am trying to convert into an array using Newtonsoft.Json . 我有一个JSON结果,我试图使用Newtonsoft.Json转换为数组。 My JSON result i get from the website is along the lines of (formated for readability): 我从网站上获得的JSON结果大致如下(为便于阅读而格式化):
{
"headers":
[
"Shift Date",
"Shift Number"
],
"values":
[
["2016-06-19T00:00:00",0],
["2016-06-19T00:00:00",2],
["2016-06-19T00:00:00",1]
]
}
Code examples I have found say that i should be able to use 我发现的代码示例说我应该可以使用
Dim arr As JArray = JArray.Parse(response.Content)
This results in an error though with: 尽管这样会导致错误:
An unhandled exception of type 'Newtonsoft.Json.JsonReaderException' occurred in Newtonsoft.Json.dll
Additional information: Error reading JArray from JsonReader. Current JsonReader item is not an array: StartObject. Path '', line 1, position 1.
Any guidance on what could be causing the issue? 关于什么可能导致此问题的任何指导? I suspect it is something with the "headers" but unable to find online any suggestions on how to resolve 我怀疑这是带有“标题”的内容,但无法在网上找到有关如何解决的任何建议
You are using JArray
but your input is actually an object - ie the data is 您正在使用JArray
但您的输入实际上是一个对象-即数据是
{..stuff..}
rather than 而不是
[ {..stuff..} ]
. [ {..stuff..} ]
。
If you restructure your input to be: 如果将输入重构为:
[{
"headers": [
"Shift Date",
"Shift Number"
],
"values": [
["2016-06-19T00:00:00", 0],
["2016-06-19T00:00:00", 2],
["2016-06-19T00:00:00", 1]
]
}]
You can then use the JArray.Parse(strJson)
method. 然后,您可以使用JArray.Parse(strJson)
方法。
In the current structure, you should use JObject.Parse
. 在当前结构中,应该使用JObject.Parse
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.