Android Question how to get a specific index of a json list?

pacoMx

Member
Licensed User
Longtime User
Hi, using the json tree viewer I was able to get values in a for - each loop.

How can I access a specific index?
I would like to access element 'Instrucciones' of object 2


This is the code for-each

B4X:
    Dim parser As JSONParser
    parser.Initialize(File.ReadString(File.DirAssets, "info.json"))
    Dim root As Map = parser.NextObject
    Dim Values As List = root.Get("Values")
    For Each colValues As Map In Values
        Dim NombreImagen As String = colValues.Get("NombreImagen")
        Dim Instrucciones As String = colValues.Get("Instrucciones")
        Dim NombreDeEscena As String = colValues.Get("NombreDeEscena")
        Dim NombreAudio As String = colValues.Get("NombreAudio")
        Dim NombreVideo As String = colValues.Get("NombreVideo")
        Log (NombreImagen & " "& Instrucciones)
    Next


json looks like:

INI:
{"Values":[{
    "NombreDeEscena":"Frontal",
    "NombreImagen" : "cp-01.png",
    "NombreVideo" : "cp1.mp4",
    "NombreAudio":"au00.mp3",
    "Instrucciones":"Fotografía  de frente"
    },
    {
        ... same structure, removed for clarity
    },
    {
... same structure, removed for clarity
    }]
    }
 
Top