Android Question B4A JSON key and index value how to get?

ronovar

Active Member
Licensed User
Longtime User
I have this JSON:

B4X:
{
    "storage": [
        ["1", "AA"],
        ["2", "BB"],
        ["3", "CC"],
        ["4", "DD"],
        ["5", "EE"],
        ["6", "FF"],
        ["7", "GG"],
        ["8", "HH"],
        ["9", "II"],
        ["10", "JJ"],
        ["11", "KK"],
        ["12", "LL"],
        ["13", "MM"],
        ["14", "NN"],
        ["15", "OO"],
        ["16", "RR"]
    ]
}

How can i get number and value of each item? I need this to put in my ListView line of apk that i im building...so i tried like this:

B4X:
'INITIALIZE - json
                JSON.Initialize(Job.GetString2("UTF8"))
               
                'NEXT - Object
                Map1 = JSON.NextObject
               
                'GET - VideoClub Items
                VideoClubItems = Map1.Get("storage")

                For i = 0 To VideoClubItems.Size - 1
                     Log(VideoClubItems.Get(i))           => Need to get index in this example => 1
                     Log(VideoClubItems.Get(i))           => Need to get index value in this example => AA
                Next

I don't know using Get(i) how to get index and index value to print using log..so that i can later add it to listview item...so if you could help me what i need to write...thanks.
 

ronovar

Active Member
Licensed User
Longtime User
Thanks i added this and it is working:

B4X:
For Each colstorage As List In VideoClubItems
                    For Each colcolstorage As String In colstorage
                        Log("colcolstorage..."&colcolstorage)
                    Next
                Next

But i need to get two values at once...so i need to use only one Log() to get id and value...if you could give example code how to do that?
 
Last edited:
Upvote 0

ronovar

Active Member
Licensed User
Longtime User
Here is using your help MarkusR and script i get this:

B4X:
For Each colstorage As List In Main.VideoClubItems
        Log("colstorage..."&colstorage.Get(0))
        Log("colstorage..."&colstorage.Get(1))
    Next

Thanks for helping me out now i get both items using index (0) and (1).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…