VB.NET将JSON字符串中的“& vbLF &“转换为可解析的格式?

mitkmikd  于 5个月前  发布在  .NET
关注(0)|答案(1)|浏览(87)

我使用VB.NET和Newtonsoft通过httpClient与API交互。我遇到了一个从API返回的字符串格式问题。这里有一个应该是JSON的返回示例。它来自变量的“copy value”。看起来它构建了字符串并返回了它。

"[" & vbLf & "    {" & vbLf & "        ""count"": 7," & vbLf & "        ""headings"": [" & vbLf & "            ""name""," & vbLf & "            ""description""" & vbLf & "        ]," & vbLf & "        ""kind"": ""Detail""," & vbLf & "        ""offset"": 0," & vbLf & "        ""results"": [" & vbLf & "            [" & vbLf & "                ""PASS - Password Complexity""," & vbLf & "                ""Verifies that password complexity is enabled on the device.""" & vbLf & "            ]," & vbLf & "

字符串
当我尝试使用

Dcontent = Await Response.Content.ReadAsStringAsync
Dim DiscJ As JObject = JObject.Parse(Dcontent)


它抛出一个错误“当前JsonReader项目不是一个对象,行1字符1”。我可以输出到一个文本框,复制到JSONLint和它验证。
我在如何把它转换成一种我可以解析的格式上画了一个空白。任何帮助都是非常感激的。我试过阅读数据作为一个流而不是字符串,但这并没有改变格式。

e5nqia27

e5nqia271#

虽然这不是必需的,但我可以使用

DContent = DContent.Replace(vbLf, "")

字符串
去掉换行符。然后我就可以使用

Dim MyArray As JArray = JArray.Parse(DContent)


感谢您指出它是一个数组而不是一个对象。

相关问题