0
我有一個Newtonsoft.Json的問題。我試圖解析來自URL的JSON,但我得到一個錯誤。這裏是JSON:Newtonsoft.Json.JsonReaderException
[
{
"ID": "0",
"Nome": "we",
"Data": "2013-09-16",
"Orario": "00:00:16",
"Prestazione": "dfg",
"Stato": "dfg",
"Numero_Telefono": "dfg"
},
{
"ID": "0",
"Nome": "fg",
"Data": "2013-09-26",
"Orario": "00:00:00",
"Prestazione": "",
"Stato": "",
"Numero_Telefono": ""
},
{
"ID": "1",
"Nome": "davide",
"Data": "2013-09-26",
"Orario": "00:00:16",
"Prestazione": "ds",
"Stato": "sd",
"Numero_Telefono": "3546"
}
]
這裏是我使用的代碼:
Dim request As HttpWebRequest
Dim response As HttpWebResponse = Nothing
Dim reader As StreamReader
Try
request = DirectCast(WebRequest.Create("http://nhd.altervista.org/connectDb.php"), HttpWebRequest)
response = DirectCast(request.GetResponse(), HttpWebResponse)
reader = New StreamReader(response.GetResponseStream())
Dim rawresp As String
rawresp = reader.ReadToEnd()
Dim jResults As JObject = JObject.Parse(rawresp)
Dim results As List(Of JToken) = jResults.Children().ToList()
For Each item As JProperty In results
item.CreateReader()
MsgBox(item.Value("img")) ' because my tag in json is img
Next
Catch ex As Exception
Console.WriteLine(ex.ToString)
MsgBox(ex.ToString)
Finally
If Not response Is Nothing Then response.Close()
End Try
這是我收到的錯誤,當我嘗試解析JSON:
Newtonsoft.Json.JsonReaderException: Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.
你能幫我解決這個問題?
這對JSON解析器非常有幫助我在寫謝謝,c#基本上是完全一樣的。 –
@ZachM。很高興你發現它很有用。 –