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
 

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
Maybe I'm missing something, I don't see an error here just a number of warnings saying that variables have not been used yet.

if you use the variables in your code then the warnings will disappear.

1626422286569.png
 
Upvote 0

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

TILogistic

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


1626459521628.png
 
Upvote 0
Top