Android Question Reading JSON from web site

engvidal

Member
Licensed User
Longtime User
Hi.

I am using the tutorial to read a json file from a text file on my computer.

Now I need to know how to request the JSON from a web site.

The address is: http://thethingsnetwork.org/api/v0/nodes/02015512/?format=json

The file is huge, but I need now only the first block of data

Attached is my app reading for the text file

Thank You

Vidal
 

Attachments

  • JSONExample.zip
    13 KB · Views: 331

DonManfred

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("Layout1")
    Dim job As HttpJob
    job.Tag = "thethingsnetwork.json"
  job.Initialize("getjson", Me)
  job.Download("http://thethingsnetwork.org/api/v0/nodes/02015512/?format=json")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub JobDone(Job As HttpJob)
    ProgressDialogHide
  If Job.Success Then
        If Job.JobName = "getjson" Then
            Dim out As OutputStream
            out = File.OpenOutput(File.DirRootExternal,Job.Tag,False )
            File.Copy2(Job.GetInputStream, out)
            out.Close
            Log($"The file ${Job.Tag} is written to DirRootExternal"$)
           
            ParseJSON(Job.GetString)
           
        End If
  Else
      Log( Job.ErrorMessage)
  End If
    Job.Release
End Sub
Sub ParseJSON(jsonstring As String)
    Dim parser As JSONParser
    parser.Initialize(jsonstring)
    Dim root As List = parser.NextArray
    For Each colroot As Map In root
        Dim rssi As Int = colroot.Get("rssi")
        Dim data_raw As String = colroot.Get("data_raw")
        Dim data As String = colroot.Get("data")
        Dim snr As Double = colroot.Get("snr")
        Dim node_eui As String = colroot.Get("node_eui")
        Dim datarate As String = colroot.Get("datarate")
        Dim time As String = colroot.Get("time")
        Dim gateway_eui As String = colroot.Get("gateway_eui")
        Dim frequency As Double = colroot.Get("frequency")
        Log($"RSSI=${rssi}
data_raw=${data_raw}
snr=${snr}
node_eui=${node_eui}
datarate=${datarate}
time=${time}
gateway_eui=${gateway_eui}
frequency=${frequency}
=====================
        "$)
    Next
End Sub
 

Attachments

  • jsonparse.zip
    7.3 KB · Views: 459
Upvote 0
Top