Thanks Atif. I'll make some notes below on the results I'm getting.
BTW, I'm in .net 2.0 and using JayRock version 0.9.8316
> When doing a generic import, the simple rule to remember is that JSON objects {...} become dictionaries (IDictionary) and JSON arrays [...] become lists (IList). The concrete types yielded are JsonObject and JsonArray if that's important to you.
>
> Given your root oJsonObject, you can access the various pieces like this...
>
> Get the logon member of the root object:
>
> Dim logon As String = oJsonObject("logon")
>
> Get the list of addresses from the root object:
>
> Dim addresses As IList = oJsonObject("addresses")
>
> Get the first address object:
>
> Dim address As IDictionary = addresses(0)
Here I tried to do this:
Response.Write(address ("firstName"))
It was equal to "Nothing" and did not output any value.
> Loop through each shipping address object and dump members:
>
> For Each shipping In address("shipping")
> Console.WriteLine(shipping("firstName"))
> Console.WriteLine(shipping("lastName"))
> ' etc.
> End
I received the following error at this point:
"Conversion from string "shipping" to type 'Integer' is not valid."
Here is my full code:
---------------------------------------------------------------------------------------------------------------------------------
Dim oTextReader As System.IO.TextReader
oTextReader = New IO.StreamReader("C:\Documents and Settings
\rtaylor\Desktop\json.txt")
Dim oJsonTextReader As New JsonTextReader(oTextReader)
Dim strString As String = String.Empty
Dim oJsonObject As New JsonObject
Dim oAddress As IDictionary
With oJsonObject
.Import(oJsonTextReader)
If .HasMembers Then
Response.Write("LogonID: " & .Item("logonId").ToString
& "<br>")
Response.Write("First Name: "
& .Item("firstName").ToString & "<br>")
Dim oAddresses As IList = oJsonObject("addresses")
oAddress = oAddresses(0)
Response.Write(oAddress("firstName"))
'Loop through each shipping address object and dump
members:
For Each oAddress In oAddresses("shipping")
Response.Write(oAddress("firstName"))
Response.Write(oAddress("lastName"))
Next
End If
End With
---------------------------------------------------------------------------------------------------------------------------------