• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 884
  • Last Modified:

Deserialize JSON

Here is my data format and code to display values from the JSON variable.  This displays all of the value for attendees.  I need to be able to display each name, email value but get lost after this.

Dim cMessage As String = "{ ""meeting_id"": 1234, " & _
            """instance_id"": 5678," & _
            """attendees"": [ " & _
            "{" & _
            """name"": ""wesgroves"", " & _
            """email"": ""wes@wes.com"", " & _
            "}" & _
            "," & _
            "{" & _
            """name"": ""wes2groves"", " & _
            """email"": ""wes2@wes2.com"", " & _
            "}" & _
            "]" & _
            "}"


        Dim objResponse As JsonObject

        'MsgBox("Last response was: " + objResponse("error")("message"))

        objResponse = CType(JsonConvert.Import(cMessage), JsonObject)

        MsgBox("Last response was: " & objResponse("attendees").ToString)
0
FTX
Asked:
FTX
1 Solution
 
FTXAuthor Commented:
Ok, with the help of https://groups.google.com/forum/?fromgroups#!topic/jayrock/k2QIwLgDTYM[1-25] which actually takes you one level deeper into a JSON response, I answered my own question:

Dim cMessage As String = "{ ""meeting_id"": 1234, " & _
            """instance_id"": 5678," & _
            """attendees"": [ " & _
            "{" & _
            """name"": ""wesgroves"", " & _
            """email"": ""wes@wes.com"", " & _
            "}" & _
            "," & _
            "{" & _
            """name"": ""wes2groves"", " & _
            """email"": ""wes2@wes2.com"", " & _
            "}" & _
            "]" & _
            "}"

        Dim root As IDictionary = JsonConvert.Import(cMessage)

        Dim meetingid As String = root("meeting_id").ToString
        MsgBox("meeting_id: " & meetingid)

        Dim instanceid As String = root("instance_id").ToString
        MsgBox("instance_id: " & instanceid)

        Dim attendees As IList = root("attendees")
        For Each attendee As IDictionary In attendees
            MsgBox("name: " & attendee("name"))
            MsgBox("email" & attendee("email"))
        Next
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now