Android Question Retrieve data from web API to b4a

Sofiya

Member
Licensed User
Hi,
I am trying to display the data from web API to dynamically generated buttons in B4A. How i do this.?
 

DonManfred

Expert
Licensed User
Longtime User
Should we guess now what Api you are talking about and what data you receive/want to use?
Use okhttputils to connect to the web-api and to receive data. Use jsonparser if the data is json.
Search the forum. There are plenty of such questions.
 
Upvote 0

MarkusR

Well-Known Member
Licensed User
Longtime User
i not test myself but i bookmark it for later use
https://www.b4x.com/android/forum/t...reate-an-app-settings-page.84570/#post-535739

this part make a get request for ms web api controller, in jobdone you get the result json, you can also use the wait for syntax at Download.
u need json & okhttputils2 lib comes with the ide.
B4X:
Sub ButtonGet_Click
  
    Dim BC As String
    BC = EditTextBC.Text

    Dim Job As HttpJob
    Job.Initialize("Job1",Me)
    Job.Username="..."
    Job.Password="..."
    Job.Download("https://domain.com/api/barcode/1?barcode=" & BC )
  
End Sub

Sub JobDone (Job As HttpJob)
  
    Log("JobName = " & Job.JobName & ", Success = " & Job.Success)
    If Job.Success = True Then
        Select Job.JobName
            Case "Job1"

                Dim JSON As JSONParser
                JSON.Initialize(Job.GetString)

                Dim Map1 As Map
                Map1 = JSON.NextObject
              
                EditTextBC.Text = Map1.Get("barcode")
                EditTextResponse.Text = Map1.Get("marking")
                LabelError.Text = Map1.Get("error")
              
                'print the result to the logs
                Log(Job.GetString)
        End Select
    Else
        Log("Error: " & Job.ErrorMessage)
        ToastMessageShow("Error: " & Job.ErrorMessage, True)
    End If
    Job.Release
  
End Sub
 
Upvote 0
Top