String cannot be converted to JSONArray

前端 未结 2 656
我在风中等你
我在风中等你 2021-01-28 04:20

I am trying to get data from a php file.

This is my PHP code:

$sql=mysql_query(\"select * from `tracking`\");
while($row=mysql_fetch_assoc($sql))
$output         


        
相关标签:
2条回答
  • 2021-01-28 04:46

    Put this lines:

            while(result.charAt(0)!='[')  //or result.charAt(0)!='{'
            {
                result = result.substring(1);
                Log.d("Tag1", "remove 1st char");
    
            }
    

    after:

            result = sb.toString();
    

    To become like this:;

            result = sb.toString();
    
            while(result.charAt(0)!='[')
            {
                result = result.substring(1);
                Log.d("Tag1", "remove 1st char");
    
            }
    
    0 讨论(0)
  • 2021-01-28 04:48

    I found what was wrong with JSON. I found at the beginning a character "?" added somewhere in the code and it was not visible until I stored the logCat entry to a file. So I added the code line and it works fine now.

    result = result.substring(1);
    

    I hope it may help someone in the future thanx to Waqas

    0 讨论(0)
提交回复
热议问题