php - Error parsing JSON data. JSONException: End of input at character -


here php code fragment parsing.

$result=mysql_query($qry);      $json="{";     for($i=1;$i<=$count;$i++)     {     $row = mysql_fetch_row($result)     $newrow=setjson($i,$row);     if($i!=$count)     $json=$json.$newrow.",";     else     $json=$json.$newrow;     }     $json=$json."}";      $response["success"]=1;     $response["count"]=$count;     $response["rows"]=$json;      echo json_encode($response); 

function creating new row

function setjson($i,$row) { $setrow="\""$i."\":[".$row."]"; return $setrow; } 

i have developed using php. trying parse mysql result following format. each row in db. need update sqlite db in app.

    {     "success":1,     "error":0,     "rows":{             "1":["abc","123"],             "2":["xxx","909"],             "3":["bcn","1bc"]         } }   {   "tag": "syncme",   "success": 1,   "error": 0,   "count": "8",   "rows": "{ \"1\":[\"porotta\",\"22\",\"652+2\",\"veg\",\"dinner\"], \"2\":[\"chicken curry\",\"90\",\"sdas\",\"veg\",\"dinner\"], \"3\":[\"assd\",\"12\",\"looo\",\"veg\",\"dinner\"]}" } 

how can remove slashes in json string.??

pass result 1 array variable using loop.

then use json_encode(array_variable);

it give proper json format..

why need format manually.

you can try way .. note: values hard coded..

for($i=1;$i<=$count;$i++) {     $json[$i]=array("abc","123"); } $response["success"]=1;     $response["count"]=3;     $response["rows"]=$json;  var_dump( json_encode($response)); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -