Android Question Data processing API

joaomoraes83

Member
Licensed User
friends, I am not able to treat the data below, indicates error in "parser.NextObject" where I am wrong?

B4X:
Sub Process_Globals

End Sub
Sub Globals

    Private Button1 As Button
    Private Label1 As Label
    Private Label2 As Label
End Sub
Sub Activity_Create(FirstTime As Boolean)

    Activity.LoadLayout("1")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
 
 

Sub ipinfo
 
    Dim GetAddressJob As HttpJob
    GetAddressJob.Initialize("GetAddress", Me)
    ‘curl -X GET --header 'Accept: application/json'

    GetAddressJob.Download("http://www.transparencia.gov.br/api-de-dados/bolsa-familia-sacado-por-nis?nis=16052206471&anoMesReferencia=201805&anoMesCompetencia=201805&pagina=1
")
    Wait For (GetAddressJob) JobDone(GetAddressJob As HttpJob)
    If GetAddressJob.Success Then
        
        Dim parser As JSONParser
        parser.Initialize(GetAddressJob.GetString)
        Dim root As Map = parser.NextObject ‘error here
         Dim id As String = root.Get("id")
        Dim nis As String = root.Get("nis")
        
      
            
        Log($"id: ${id}"$)
        Log($"nis: ${nis}"$
        Label1.Text=id
        Label2.Text=nis
 
    End If
 
    GetAddressJob.Release
 
End Sub

sub Button1_click
      
      ipinfo
end sub
 

DonManfred

Expert
Licensed User
Longtime User
http://basic4ppc.com:51042/json/index.html

B4X:
Dim parser As JSONParser
parser.Initialize(GetAddressJob.GetString)
Dim root As List = parser.NextArray
For Each colroot As Map In root
 Dim municipio As Map = colroot.Get("municipio")
 Dim uf As Map = municipio.Get("uf")
 Dim sigla As String = uf.Get("sigla")
 Dim nome As String = uf.Get("nome")
 Dim nomeIBGE As String = municipio.Get("nomeIBGE")
 Dim codigoIBGE As String = municipio.Get("codigoIBGE")
 Dim pais As String = municipio.Get("pais")
 Dim beneficiarioBolsaFamilia As Map = colroot.Get("beneficiarioBolsaFamilia")
 Dim nis As String = beneficiarioBolsaFamilia.Get("nis")
 Dim nome As String = beneficiarioBolsaFamilia.Get("nome")
 Dim id As String = colroot.Get("id")
 Dim dataMesReferencia As String = colroot.Get("dataMesReferencia")
 Dim dataSaque As String = colroot.Get("dataSaque")
 Dim valorSaque As Double = colroot.Get("valorSaque")
 Dim dataMesCompetencia As String = colroot.Get("dataMesCompetencia")
Next
 
Upvote 0
Top