Hi community oh written an app that through a php script receives data from the mysql db on my server. everything worked but since I inserted the 'RealEscape string' method, it didn't work anymore. I removed the 'RealEscape String' function and brought the php script back to the origins and now I get this error:
org.json.JSONException:
at org.json.JSONTokener.syntaxError(JSONTokener.java:449)
at org.json.JSONTokener.nextValue(JSONTokener.java:97)
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:60)
at b4a.example.main._jobdone(main.java:986)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
org.json.JSONException:
at org.json.JSONTokener.syntaxError(JSONTokener.java:449)
at org.json.JSONTokener.nextValue(JSONTokener.java:97)
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:60)
at b4a.example.main._jobdone(main.java:986)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:339)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA$2.run(BA.java:360)
at android.os.Handler.handleCallback(Handler.java:907)
at android.os.Handler.dispatchMessage(Handler.java:105)
at android.os.Looper.loop(Looper.java:216)
at android.app.ActivityThread.main(ActivityThread.java:7625)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)
Json code to receive data:
Sub JobDone(Job As HttpJob)
If Job.Success Then
Dim res As String
res = Job.GetString
Dim parser As JSONParser
parser.Initialize(res)
Dim List1 As List
List1.Initialize
List1 = parser.NextArray 'returns a list with maps
If List1.Size>0 Then
For i = 0 To List1.Size - 1
Dim Root As Map
Root=CreateMap("Tablet":Tablet,"Nome_Attivita":NomeAttivita,"ID":ID)
Root=List1.Get(i)
ListaServer.ID=Root.Get("ID")
ListaServer.Tablet=Root.Get("Tablet")
ListaServer.NomeAttivita=Root.Get("Nome_Attivita")
ListAttvita.Add("/ ID :"&Root.Get("ID")&"="&Root.Get("Nome_Attivita")&"-"&Root.Get("Tablet"))
Log(ListAttvita.Get(i))
Next
For i = 0 To ListAttvita.Size - 1
SpinnerActivity.Add(ListAttvita.Get(i))
Next
Else
ToastMessageShow("Non ci sono Attività aggiunte!",True)
End If
Else
Log(Job.ErrorMessage)
ToastMessageShow("Error: " & Job.ErrorMessage, True)
End If
Job.Release
End Sub
B4X:
public Sub GetActivity
ExecuteRemoteQuery("SELECT Tablet,ID,Nome_Attivita FROM Service_Team","")
End Sub
Sub ExecuteRemoteQuery(Query As String, JobName As String)
Dim job As HttpJob
job.Initialize(JobName, Me)
job.PostString("https://www.xxxxxxx.com/Client/ScriptAdd_UserServer.php", Query)
End Sub
php code, file present on the server.:
<?php
$databasehost = "localhost";
$databasename = "namedb"; //hidden data
$databaseusername ="nameuser"; //hidden data
$databasepassword = "passwordDB"; //hidden data
$con = mysqli_connect($databasehost,$databaseusername,$databasepassword, $databasename) or die(mysqli_error($con));
mysqli_set_charset ($con , "utf8");
$query = file_get_contents("php://input");
$sth = mysqli_query($con, $query);
if (mysqli_errno($con))
{
header("HTTP/1.1 500 Internal Server Error");
echo $query.'\n';
echo mysqli_error($con);
}
else
{
$rows = array();
while($r = mysqli_fetch_assoc($sth))
{
$rows[] = $r;
}
$res = json_encode($rows,True);
echo $res;
mysqli_free_result($sth);
}
mysqli_close($con);
?>
Last edited: