I’m hoping that someone can help me to work out where I am going wrong with this.
I have a simple JSON file, here is a condensed version of it.
[
{
"LocationGuid":"c35e549f-ffb8-4828-8290-d66c2f9b735f",
"Name":"Volkswagen",
"FolderPath":"C:\\temp\\Volkswagen"
},
{
"LocationGuid":"814e7584-9f99-40a6-8520-3f5d467ea8d9",
"Name":"Nissan",
"FolderPath":"C:\\temp\\Nissan"
},
{
"LocationGuid":"51d60458-01ac-421d-8fb8-3663f5963fbf",
"Name":"Ford",
"FolderPath":"C:\\temp\\Ford"
}
]
I want to separate the data into rows.
The following code compiles...
Private Sub UpdateExMailLocations(sPath As String)
Dim sLocationGUID As String
Dim sName As String
Dim sFolderPath As String
'' Retrieve the whole JSON file
Dim rawJSON = File.ReadAllText(sPath)
'' Parse it into JSON items
Dim jsonObject As JObject = JObject.Parse(rawJSON)
Dim jsonArray As JArray = jsonObject("result")
For Each item As JObject In jsonArray
sLocationGUID = item.SelectToken("LocationGUID").ToString
sName = item.SelectToken("Name").ToString
sFolderPath = item.SelectToken("FolderPath").ToString
MsgBox("Record = " & sLocationGUID & "," & sName & "," & sFolderPath)
Next
End Sub
When it reaches the statement:
Dim jsonObject As JObject = JObject.Parse(rawJSON)
It throws the following exception:
Newtonsoft.Json.JsonReaderException: 'Error reading JObject from JsonReader. Current JsonReader item is not an object: StartArray. Path '', line 1, position 1.'
I am a complete novice so you may have to spell out the solution in simple terms :-)