Parsing json data

jegadk

Member
Licensed User
Longtime User
Hi.

Have a problem parsing some json data. Data is from a community webservice. I have saved the data to schools.txt to use it in Erel's json sample project

I have my own webserver with a lot of webservices in json format. All works fine, but this one is a paine. I get different errors, depending on what i write in:

m = Map1.Get("???????")
m = m.Get("????????")
schoolList = m.Get("????????")

I need quick help because i need it to demonstrate how to get the community data in an app.

Attached is a sample project with data txt file.
 

Attachments

  • jsontest.zip
    8.6 KB · Views: 217

agraham

Expert
Licensed User
Longtime User
B4X:
Sub Activity_Create(FirstTime As Boolean)
   'Do not forget to load the layout file created with the visual designer. For example:
   Activity.LoadLayout("Main")
   Dim JSON As JSONParser
   Dim Map1 As Map
   JSON.Initialize(File.ReadString(File.DirAssets, "schools.txt"))
   Map1 = JSON.NextObject
   
   Dim m As Map
   Dim featuresList As List
   
   featuresList = Map1.Get("features")
   Msgbox(featuresList.Get(0),"")
   For i = 0 To featuresList.Size - 1
      m = featuresList.Get(i)
      m = m.Get("properties")
      ListView1.AddTwoLines2(m.Get("navn"),m.Get("adresse"),m.Get("id"))
   Next

End Sub
 
Upvote 0
Top