0

I have json format like below :

{"response":[{Pasien={id=24, name=Erren}, Detailtransaksi=[], Upk={name=Poli Umum}, Pendaftaran={antrian=1, id=1, user_id=9, modified=2015-03-01 14:08:46, keterangan=demam tinggi, pasien_id=24}},
 {Pasien={id=21, name=Lulu Batam}, Detailtransaksi=[], Upk={name=Poli Umum}, Pendaftaran={antrian=2, id=2, user_id=9, modified=2015-03-01 14:09:05, keterangan=kantong kering akut, pasien_id=21}}
]}

but I don't know,how to take the array data into the list.

janisz
  • 6,292
  • 4
  • 37
  • 70
LuckyMan
  • 1
  • 2

2 Answers2

0

I tried to tell each symbole what does mean. You must use

 Dim j as Json: j.Initialize(string)
 Dim m as Map = j.NextObject()
 Dim l as List = m.Get("response")
 Dim m2 as Map = l.Get(0)
 Dim m3 as Map = m2.Get("Pasien")
 Dim id as Integer = m3.Get("id")
 Dim l2 as List = m3.Get("Detailtransaksi") 'but it has not child element

these lines telling to reach data from json.

I hope these tips enough for you.

{  => this mean it is a json object. you must take this to Map by nextObject       

'response':[   => this mean it is a list! you must take this element to List by nextArray
      {        => after take all data to list, get every element from list to Map
         Pasien={   => get "Pasien" value from Map with own key to new Map
                  id=24,   
                  name=Erren
                }, 
         Detailtransaksi=[], 
         Upk={
               name=Poli Umum
             }, 
         Pendaftaran={
                       antrian=1, 
                       id=1, 
                       user_id=9, 
                       modified=2015-03-01 14:08:46,
                       keterangan=demam tinggi, pasien_id=24
                     }
       },

       {
          Pasien={
                    id=21, 
                    name=Lulu Batam
                  }, 
          Detailtransaksi=[],
          Upk={
                name=Poli Umum
              },
          Pendaftaran={
                        antrian=2,
                        id=2, 
                        user_id=9,
                        modified=2015-03-01 14:09:05,
                        keterangan=kantong kering akut, 
                        pasien_id=21
                       }
         }
   ]
}
Serhat MERCAN
  • 1,078
  • 3
  • 14
  • 31
0

You can use JSONParser class. First you should add the JSON library to your project, then declare a JSONParser variable and initialize it with your JSON text.

Now you can use the following two methods to get the result: parser.NextArray As List (when there are more than one element in JSON text) parser.NextObject As Map (when there is only one object in the json text)

private Sub ParseResponse (text As String) As List
parser.Initialize(text)
Private returnList As List
Private jsonMap As Map
Private jsonList As List

Try
    jsonList = parser.NextArray
    returnList = jsonList
    Return returnList
Catch
    Try
        jsonMap = parser.NextObject
        returnList.Add(jsonMap)
        Return returnList
    Catch
        Return Null     ' not a json text
    End Try
End Try

End Sub