Android Question JSON Array expected

ilan

Expert
Licensed User
Longtime User
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:

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
 

ilan

Expert
Licensed User
Longtime User
(Switch to jRDC2. Simpler, more powerful and better performance)

I would love too, but a private server is very expensive and for now, I don't make enough profit for that. if it will get better I will definitely switch to jrdc2
 
Upvote 0

ilan

Expert
Licensed User
Longtime User
Upvote 0

ilan

Expert
Licensed User
Longtime User
btw. i think i already asked you once by why does not Anywhere Software also offer Hosting Service? You already are dealing with it (B4i Hosted Builder)
i am sure a lot will use your service (including me)
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…