Android Question json read error

jchal

Active Member
Licensed User
Longtime User
hi all
i tryed to read this json
{"draw":{"drawTime":"21-07-2017T10:00:00","drawNo":626098,"results":[65,72,45,27,80,3,1,17,20,52,79,56,30,50,69,8,43,22,23,32]}}

but i got the error below

the code i used in order toread this is
B4X:
Sub LoadKdraw
    Dim jobadd As HttpJob
    jobadd.Initialize("kdraw", Me)
    jobadd.Download("http://mydomainname.com/last.json")
    ProgressDialogShow("Downloading kdraw")
End Sub


Sub JobDone (Job As HttpJob)
    ProgressDialogHide
    If Job.Success = True Then
        Dim strReturn As String = Job.GetString
        Dim parser As JSONParser
        parser.Initialize(strReturn)
        If Job.JobName = "kdraw" Then
            Dim quizlist As List
            'Dim strOnline As String
            quizlist = parser.NextArray 'returns a list with maps
            For i = 0 To quizlist.Size - 1
                Dim m As Map
                m = quizlist.Get(i)
                Dim TL As quizpar 'TwoLines
              
                TL.First = m.Get("kdraw")
                TL.Second = m.Get("kresult1")
                TL.third=m.Get ("kresult2")
                TL.forth=m.Get ("kresult3")
                TL.five=m.Get("kresult14")
                TL.six=m.Get("kresult15")
              
                Label1.Text= TL.First
                Label2.Text=TL.Second
                Label3.Text=TL.third
                Label4.Text=TL.forth
                Label5.Text=TL.five
                Label6.text=TL.six
                Exit
              
            Next
        Else If Job.JobName = "LogOut" Then
            Dim act As String = parser.NextValue
            If act = "LoggedOut" Then
                ToastMessageShow("Logout successful", True)
                StartActivity(Main)
                Activity.Finish
            End If
        Else
            ToastMessageShow("Error: Invalid Value", True)
        End If
    Else
        'Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub
 

jchal

Active Member
Licensed User
Longtime User
i know but i dont understand how to fix itm what is the eror i am doing and how can i corrected?
 
Upvote 0

eps

Expert
Licensed User
Longtime User
The tool Erel mentioned can give you a hint about the code you need to put in place to traverse your JSON correctly, using the link above and your JSON it gives the following :

B4X:
Dim parser As JSONParser 
parser.Initialize(<text>) 
Dim root As Map = parser.NextObject 
Dim draw As Map = root.Get("draw") 
Dim drawTime As String = draw.Get("drawTime") 
Dim drawNo As Int = draw.Get("drawNo") 
Dim results As List = draw.Get("results") 
For Each colresults As Int In results 
Next
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…