JSON Parsing Problem

Johnmcenroy

Active Member
Licensed User
Longtime User
I have a JSON file:
{ "report" : [{"date":"2013-05-27","site_name":"Ideal Weight (BMI,BMR,etc.)","requests":"31","impressions":"29","clicks":"5","fill":"0.9355","ecpm":"8.6207","earnings":"0.2500","zone_name":"Phone - Banner"}
]}

My parsing code:
B4X:
Dim JSON As JSONParser
    Dim Map1 As Map
    JSON.Initialize(File.ReadString(File.DirInternal, "TapitJSON"))
    Map1 = JSON.NextObject
    Dim reportStats As List
    reportStats = Map1.Get("report")
    For i = 0 To reportStats.Size - 1
     Log(i & " " & reportStats.Get(i) & " ")
    Next

I get :
0 {earnings=0.5500, impressions=63, requests=66, ecpm=8.7302, zone_name=Phone - Banner, fill=0.9545, clicks=11, site_name=Ideal Weight (BMI,BMR,etc.), date=2013-05-27}

Can i get values separately from this JSON , for example "earning" in one string and "0.5500" in another string ?

Thanks
 

Johnmcenroy

Active Member
Licensed User
Longtime User
I have done
B4X:
Dim JSON As JSONParser
    Dim Map1 As Map
    JSON.Initialize(File.ReadString(File.DirInternal, "TapitJSON"))
   Map1 = JSON.NextObject
   Dim m As Map 'helper map for navigating
   Dim MenuItems As List
   MenuItems = Map1.Get("report")
   For i = 0 To MenuItems.Size - 1
      m = MenuItems.Get(i)
      lblTapitClicks.Text = m.Get("clicks")
       lblTapitEarnings.Text = m.Get("earnings") & " $"
       lblTapitEcpm.Text = m.Get("ecpm") & " $"
       lblTapitFill.Text = m.Get("fill")*100
      lblTapitFill.Text = lblTapitFill.Text & " %"
       lblTapitImpressions.Text = m.Get("impressions")
       lblTapitRequests.Text = m.Get("requests")
   Next

:icon_clap:
 
Upvote 0
Top