hi
i am trying to get the entires from my mysql db via php but what i get is an error saying JSON array expected...
this is the log:
this is the code:
and php code:
what am i doing wrong?
thanx
i am trying to get the entires from my mysql db via php but what i get is an error saying JSON array expected...
this is the log:
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
*** Service (httputils2service) Create ***
** Service (httputils2service) Start **
[{"id":"3","title":"דרושים כוונים CNC לכרסום וחריטה","date":"30-07-2019","fav":"0","title2":"גולדברגר טכנולוגיות","jobexp":"לחברת גולדברגר טכנולוגיות הממוקמת בא.ת בר לב (ליד כרמיאל), דרושים כוונים CNC לכרסום וחריטה.\r\n*משרה מלאה.\r\n*אווירה נעימה ואיכותית!\r\n*תנאים טובים מאד למתאימים\/ות.","jobneeds":"- ניסיון קודם - חובה.\r\n- ראש גדול, מוסר עבודה וחריצות.\r\n*המשרה מיועדת לנשים וגברים כאחד.","experience":"1-2","category":"CNC, כרסם - חרט","place":"צפון","period":"משרה מלאה","price":"0","publisher":"גולדברגר","pubemail":"reut@gmt.co.il","pubid":"1","startdatetime":"00000000000","enddatetime":"00000000000","status":"0"}]
Error occurred on line: 82 (jobs)
java.lang.RuntimeException: JSON Array expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextArray(JSONParser.java:62)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:348)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:176)
at anywheresoftware.b4a.shell.DebugResumableSub$RemoteResumableSub.resume(DebugResumableSub.java:22)
at anywheresoftware.b4a.BA.checkAndRunWaitForEvent(BA.java:250)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:137)
at anywheresoftware.b4a.BA$2.run(BA.java:370)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
this is the code:
B4X:
Sub loadalljobs As ResumableSub
jobsclv.Clear
Dim j As HttpJob
j.Initialize("", Me)
j.Download2("http://www.sagital.net/msjobs4.php", Array As String ("action", "getjobs"))
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Log(UnescapeUnicode(j.GetString))
Dim parser As JSONParser
parser.Initialize(UnescapeUnicode(j.GetString))
Dim root As List = parser.NextArray
Log(root.Size)
End If
j.Release
Return True
End Sub
Sub UnescapeUnicode(s As String) As String
Dim sb As StringBuilder
sb.Initialize
Dim i As Int
Do While i < s.Length
Dim c As Char = s.CharAt(i)
If c = "\" And i < s.Length - 1 And s.CharAt(i + 1) = "u" Then
Dim unicode As StringBuilder
unicode.Initialize
i = i + 2
Do While i < s.Length
Dim cc As String = s.CharAt(i)
Dim n As Int = Asc(cc.ToLowerCase)
If (n >= Asc("0") And n <= Asc("9")) Or (n >= Asc("a") And n <= Asc("f")) Then
unicode.Append(s.CharAt(i))
Else
i = i - 1
Exit
End If
i = i + 1
Loop
sb.Append(Chr(Bit.ParseInt(unicode.ToString, 16)))
Else
sb.Append(c)
End If
i = i + 1
Loop
Return sb.ToString
End Sub
and php code:
B4X:
Case "getjobs":
$q = mysqli_query($con, "SELECT * FROM $table ORDER BY id");
$rows = array();
while($r = mysqli_fetch_assoc($q))
{
$rows[] = $r;
}
print json_encode($rows);
mysqli_free_result($q);
break;
what am i doing wrong?
thanx