Android Question JSON RESULTS TO SPINNER

Douglas Farias

Expert
Licensed User
Longtime User
HI
how can i know how many results have on my json
for exemple

i make this query to return me all citys
B4X:
    Sub verificausuario
        ExecuteRemoteQuery("SELECT Cidade FROM cidades" , resultadocidades)
    End Sub

ok this show me

[{"Cidade":"S\u00e3o Leopoldo"},{"Cidade":"Porto Alegre"},{"Cidade":"Canoas"},{"Cidade":"Novo Hamburgo"}]


i try make this to take the values


B4X:
    Dim listaface As List
        Dim nomecompleto As String
        Dim parserface As JSONParser
        Dim mface As Map
     
        mface.Initialize
        parserface.Initialize(respostadoservidor)
        listaface.Initialize
     
        listaface = parserface.NextArray
        mface = listaface.Get(0)
        nomecompleto = mface.Get("Cidade") 'THIS SHOW ME SÃO LEOPOLDO 1°
        Msgbox(nomecompleto, "teste") '
        mface = listaface.Get(1)
        nomecompleto2 = mface.Get("Cidade") 'THIS SHOW ME PORTO ALEGRE 2°
        Msgbox(nomecompleto, "teste")

OK i know return a value 0 1 2 3 4
but have a way to make this count automatic?
I dont want update my app all time
when i add a new city on the database automatic this add on my spinner

for exemple
i m add a new city on the table database
how can i get this all values to put on a spinner
how can i know all values to make a Get(0) Get(1) etc

if i have 40 citys on my db have a way to take this 40 citys to put on my spinner?

spinnercidade.AddAll(Array As String(nomecompleto,nomecompleto2)
 

Douglas Farias

Expert
Licensed User
Longtime User
ty man
i tryed with

B4X:
        For i = 0 To listaface.Size - 1
        Next
        mface = listaface.Get(i)
but dont work

your code works fine very thx man
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
HI
how can i know how many results have on my json
for exemple

this show me

[{"Cidade":"S\u00e3o Leopoldo"},{"Cidade":"Porto Alegre"},{"Cidade":"Canoas"},{"Cidade":"Novo Hamburgo"}]

I have a nice link for you. Maybe you don´t know it...

http://basic4ppc.com:51042/json/index.html

- Call the url.
- Copy your json-string into the upper left memo
[{"Cidade":"S\u00e3o Leopoldo"},{"Cidade":"Porto Alegre"},{"Cidade":"Canoas"},{"Cidade":"Novo Hamburgo"}]
- Press PARSE
- You then get the right code to "read" this JSON-String in the bottom left memo

B4X:
Dim parser As JSONParser
parser.Initialize(<text>)
Dim root As List = parser.NextArray
For Each colroot As Map In root
Dim Cidade As String = colroot.Get("Cidade")
Next
 
Upvote 0
Top