Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 使用NewtonSoft循环JSON_Asp.net_Json_Vb.net_Json.net - Fatal编程技术网

Asp.net 使用NewtonSoft循环JSON

Asp.net 使用NewtonSoft循环JSON,asp.net,json,vb.net,json.net,Asp.net,Json,Vb.net,Json.net,我的JSON文件中有6300多条消息。我的JSON格式如下 { "messages":[ { "id": ... } ... ]} 我正在尝试使用NewtonSoft循环浏览此JSON文件中的每条消息,使用以下代码 Dim jObj As JObject = JObject.Parse(File.ReadAllText(outputJSONpath & "myFileName.json")) Dim jArr As New JArray(jObj("messages")

我的JSON文件中有6300多条消息。我的JSON格式如下

{ "messages":[
  {
    "id": ...
  }
...
]}
我正在尝试使用NewtonSoft循环浏览此JSON文件中的每条消息,使用以下代码

Dim jObj As JObject = JObject.Parse(File.ReadAllText(outputJSONpath & "myFileName.json"))
Dim jArr As New JArray(jObj("messages"))
For Each message As JObject In jArr.Children(Of JObject)()
    'Do work
Next
当我计算JObject.Count的jArr.ChildrenOf时,我得到0。我希望能看到6300人。在即时窗口中,我看到jObj和jArr的有效对象。我以前成功地使用过类似的代码,但我不知道这里出了什么问题。我在jsonlint.com上验证了我的JSON是有效的,我想我可能有损坏的JSON。有什么想法吗?

因为消息是一个JArray,您只需将其转换为:

Dim jArr As JArray = CType(jObj("messages"), JArray)

谢谢@kblok!你搞定了@kblock For Each message As JObject In jarr.ChildrenOf JObject Dim threadID=message.SelectTokenthread\u ID它告诉我消息未声明。为什么不尝试将此循环用于jarr中的每条消息作为JObject?结果相同。消息未声明。在本地测试,它是jArr。值: