Json encode array with php - array() becomes "Array{...}" not "[...]"

mipmap

I'm trying to encode a response array as json and it has worked until now.

$response = array();
$response['icons']= $icons_arr;
$response['message']= $msg;

echo json_encode( $response );

The result is

Array{"icons":["{\r\n\t\t\t\t\t\"icon_web_id\": \t\t\t\"0 ... 

Javascript throws an error as it can't parse the "Array" word. I suspect the JQuery function $.parseJSON() expects a {} or a [].

What am I doing wrong here? Why won't json_encode() function properly?

Bonus question: what is causing all these \t\t\t\t's to occur?

Paul Dixon

Some other piece of code is producing the 'Array' output before the json string is output, you can prove this by changing the output line to

echo "json_encode returned ".json_encode( $response );

Check your code for other echo statements.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related