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 o_O

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

(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=achou.ganhou.vallow/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (logar) Create, isFirst = true **
** Activity (logar) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Array[{"NomeCompleto":"Douglas Farias"}]
Error occurred on line: 110 (logar)
java.lang.RuntimeException: JSON Array expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:62)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA$3.run(BA.java:319)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **


when i try

parserface.NextValue give me error on line 112 o_O

(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=achou.ganhou.vallow/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (logar) Create, isFirst = true **
** Activity (logar) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Array[{"NomeCompleto":"Douglas Farias"}]
Error occurred on line: 112 (logar)
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA$3.run(BA.java:319)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
 

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")


(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=achou.ganhou.vallow/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (logar) Create, isFirst = true **
** Activity (logar) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Array[{"UserID":"13","Metodo":"0","SocID":"Nativo","Senha":"asda","NomeCompleto":"Douglas Farias","Email":"doidloko@gmail.com","FacebookID":null}]
Error occurred on line: 112 (logar)
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA$3.run(BA.java:319)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=achou.ganhou.vallow/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (logar) Create, isFirst = true **
** Activity (logar) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Array[{"UserID":"13","Metodo":"0","SocID":"Nativo","Senha":"asda","NomeCompleto":"Douglas Farias","Email":"doidloko@gmail.com","FacebookID":"teste"}]
Error occurred on line: 112 (logar)
java.lang.ClassCastException: java.lang.String cannot be cast to java.util.List
at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA$3.run(BA.java:319)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=achou.ganhou.vallow/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (logar) Create, isFirst = true **
** Activity (logar) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Array[{"UserID":"13","Metodo":"0","SocID":"Nativo","Senha":"asda","NomeCompleto":"Douglas Farias","Email":"doidloko@gmail.com","FacebookID":"teste"}]
Error occurred on line: 110 (logar)
java.lang.RuntimeException: JSON Array expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:62)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA$3.run(BA.java:319)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=achou.ganhou.vallow/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (logar) Create, isFirst = true **
** Activity (logar) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Array[{"UserID":"13","Metodo":"0","SocID":"Nativo","Senha":"asda","NomeCompleto":"Douglas Farias","Email":"doidloko@gmail.com","FacebookID":"teste"}]
Error occurred on line: 110 (logar)
java.lang.RuntimeException: JSON Array expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:62)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA$3.run(BA.java:319)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
(Intent) Intent { act=android.intent.action.MAIN flg=0x20000000 cmp=achou.ganhou.vallow/.main }
no extras
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
** Activity (main) Pause, UserClosed = false **
** Activity (logar) Create, isFirst = true **
** Activity (logar) Resume **
** Service (httputils2service) Create **
** Service (httputils2service) Start **
Array[{"UserID":"13","Metodo":"0","SocID":"Nativo","Senha":"asda","NomeCompleto":"Douglas Farias","Email":"doidloko@gmail.com","FacebookID":"teste"}]
Error occurred on line: 110 (logar)
java.lang.RuntimeException: JSON Array expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:62)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
at anywheresoftware.b4a.BA$3.run(BA.java:319)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
 
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
Top