Android Question Read JSON item data in B4A

Mbotais

New Member
I want to read JSON data, like the code but error
Screenshot (348).png


this is the code :
B4X:
Sub Button1_Click
    Dim j As HttpJob
    j.Initialize("", Me)
    j.Download("http://103.124.137.197/NAPI/api/read_barang.php")
    Wait For (j) JobDone(j As HttpJob)
    If j.Success Then
        Log(j.GetString)
        Dim parser As JSONParser
        parser.Initialize(j.GetString)
        Dim root As List = parser.NextArray
        For Each colroot As Map In root
            Dim ST_ID As String = colroot.Get("ST_ID")
            Dim BR_DISKON As String = colroot.Get("BR_DISKON")
            Dim BR_ID As String = colroot.Get("BR_ID")
            Dim BR_STOK As String = colroot.Get("BR_STOK")
            Dim BR_SAT As String = colroot.Get("BR_SAT")
            Dim BR_HARGA As String = colroot.Get("BR_HARGA")
            Dim STU_NAMA As String = colroot.Get("STU_NAMA")
            Dim BR_NAME As String = colroot.Get("BR_NAME")
        Next
    End If
    j.Release
End Sub
 

thinktank

Member
use this tool by b4x team to parse json...
B4J - JSON Tree Example (b4x.com)

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As List = parser.NextArray
For Each colroot As Map In root
 Dim ST_ID As String = colroot.Get("ST_ID")
 Dim BR_DISKON As String = colroot.Get("BR_DISKON")
 Dim BR_ID As String = colroot.Get("BR_ID")
 Dim BR_STOK As String = colroot.Get("BR_STOK")
 Dim BR_SAT As String = colroot.Get("BR_SAT")
 Dim BR_HARGA As String = colroot.Get("BR_HARGA")
 Dim STU_NAMA As String = colroot.Get("STU_NAMA")
 Dim BR_NAME As String = colroot.Get("BR_NAME")
Next
 
Upvote 0

Omar Parra A.

Expert
Licensed User
Longtime User
you can use this tool to generate the api read code.


1626459521628.png
 
Upvote 0
Top