Android Question Download JSON file and turn it into strings.

TheSketchees

Member
Licensed User
Longtime User
Hello Guys,
I'm wanting to download this JSON file (https://thingspeak.com/channels/144263/feed/last.json) and turn it into strings for my app. I've managed to write the part for the parser and when manually downloaded it works. But I cannot seem to get my head around HttpUtils2 to download this as a string.

This is the part i got so far.
B4X:
Dim parser As JSONParser
    parser.Initialize(The JSON FILE HERE)
    Dim root As Map = parser.NextObject
    Dim field1 As String = root.Get("field1")
    Dim created_at As String = root.Get("created_at")
    Dim field3 As String = root.Get("field3")
    Dim entry_id As Int = root.Get("entry_id")
    Dim field2 As String = root.Get("field2")
    Dim field4 As String = root.Get("field4")
    Log(field1)

Thanks,
Alex
 

TheSketchees

Member
Licensed User
Longtime User
I now have it working actually.
B4X:
Sub CheckTempSub
    Dim CheckTemp As HttpJob
    CheckTemp.Initialize("CheckTemp", Me)
    CheckTemp.Download("https://thingspeak.com/channels/144263/feed/last.json")
    CheckTemp.Release
End Sub
Sub JobDone (Job As HttpJob)
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "Job"
                'print the result to the logs
                Log("OpenBot" & Job.GetString)
            Case "CheckTemp"
                Log("CheckTemp" & Job.GetString)
                Dim parser As JSONParser
                parser.Initialize(Job.GetString)
                Dim root As Map = parser.NextObject
                Dim field1 As String = root.Get("field1")
                Dim created_at As String = root.Get("created_at")
                Dim field3 As String = root.Get("field3")
                Dim entry_id As Int = root.Get("entry_id")
                Dim field2 As String = root.Get("field2")
                Dim field4 As String = root.Get("field4")
                Log(field1)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
End Sub

But when i click it a second time i get the error
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…