Android Question [Resolved]java.lang.RuntimeException: JSON Array expected.

Douglas Farias

Expert
Licensed User
Longtime User
hi i m trying to get my database result in array
when i execute the query it show me

respostadoservidor is string

respostadoservidor = "Array[{"NomeCompleto":"Douglas Farias"}]"

OK I HAVE ONE ARRAY WITH MY COMPLETE NAME

but i have error to get("NomeCompleto")

i m trying to use parserface.NextArray and parserface.NextValue
and show me error

here is the codes and logs
B4X:
        Dim listaface As List
        Dim contaface As String
        Dim parserface As JSONParser
        Dim mface As Map
        Dim contaface As String
       
        mface.Initialize
        parserface.Initialize(respostadoservidor) 
        listaface.Initialize
   
        listaface = parserface.NextArray  'line 110
       
        mface = listaface.Get(0) 'line 112
        contaface = mface.Get("NomeCompleto")



when i try parserface.NextArray this give error on this line



when i try

parserface.NextValue give me error on line 112

 

DonManfred

Expert
Licensed User
Longtime User
hi i m trying to get my database result in array
when i execute the query it show me

respostadoservidor = "Array[{"NomeCompleto":"Douglas Farias"}]"

Where did you get the content of respostadoservidor? It is not a valid json-string...
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
PHP:
<?

$databasehost = "localhost";
$databasename = "achou";
$databaseusername ="root";
$databasepassword = "";

$con = mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error());
mysql_select_db($databasename) or die(mysql_error());
mysql_query("SET CHARACTER SET utf8");
$query = file_get_contents("php://input");
$sth = mysql_query($query);

if (mysql_errno()) {
    header("HTTP/1.1 500 Internal Server Error");
    echo $query.'\n';
    echo mysql_error();
}
else
{
    $rows = array();
    while($r = mysql_fetch_assoc($sth)) {
        $rows[] = $r;
        echo $rows;
    }
    print json_encode($rows);
}
?>



B4X:
  Sub verificausuario
        ExecuteRemoteQuery("SELECT * FROM usuarios WHERE Email='"&email.Text&"' AND Senha='"&senha.Text&"'" , resultadoconfereusuario)
    End Sub


result = Array[{"UserID":"13","Metodo":"0","SocID":"Nativo","Senha":"asda","NomeCompleto":"Douglas Farias","Email":"doidloko@gmail.com","FacebookID":"teste"}]

later i get the result i try



B4X:
        Dim listaface As List
        Dim contaface As String
        Dim parserface As JSONParser
        Dim mface As Map
        Dim contaface As String
       
        mface.Initialize
        parserface.Initialize(respostadoservidor) 'PEGA A RESPOSTA EM JSON
        listaface.Initialize
   
        listaface = parserface.NextArray 'PEGAMOS OS DADOS VINDOS DA QUERY DE CONFERIR USUARIO NA DB

        mface = listaface.Get(0)

        contaface = mface.Get("NomeCompleto")

        Msgbox(contaface,"teste")


 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
do a
B4X:
log (Job.Getstring)
in JobDone. What does the log-command print to your log?

BTW: REMOVE THE LINE
PHP:
echo $rows;
!!

As i wrote in the thread where i gave you the tip with json_encode. ONLY echo this one command. NOT MORE... But you are echoing more! WHY THE HELL YOU ARE DOING THAT???

In jobdone you should ONLY get the jsonstring (NO ONE BYTE MORE!) back from your php-script

Douglas. If you go ahead with your bullshit of "copy and paste coding without learning or understanding what you are doing" (ignoring every tip you get)...

Please don´t expect answers from me in the future...
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
i not coping and paste DonManfred
i make the register updates etc alone
i have this error only when i trying to make a login in my app

register is 100% with facebook google and byapp
i really dont see this echo *-* i put this yesterday to test a row result

i go try remove this
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
realy is the echo

this is what need bacis realy the echo
i put this echo to test yesterday the result values

now log is
[{"UserID":"13","Metodo":"0","SocID":"Nativo","Senha":"asda","NomeCompleto":"Douglas Farias","Email":"doidloko@gmail.com","FacebookID":"teste"}]

not
Array[{"UserID":"13","Metodo":"0","SocID":"Nativo","Senha":"asda","NomeCompleto":"Douglas Farias","Email":"doidloko@gmail.com","FacebookID":"teste"}]

sory this is my error
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
B4X:
Dim parser As JSONParser
parser.Initialize(Job.Getstring)
Dim root As List = parser.NextArray
For Each colroot As Map In root
Dim FacebookID As String = colroot.Get("FacebookID")
Dim Senha As String = colroot.Get("Senha")
Dim Metodo As String = colroot.Get("Metodo")
Dim SocID As String = colroot.Get("SocID")
Dim Email As String = colroot.Get("Email")
Dim UserID As String = colroot.Get("UserID")
Dim NomeCompleto As String = colroot.Get("NomeCompleto")
Next
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…