javascript - JSON.parse from php's json_encode issue -


running issue parsing json recieved php backend. on php have array, send json_encode:

$result[] = (object) array('src' => "{$mergedfile}", 'thumb_src' => "{$thumb_file}"); echo json_encode($result); 

and when trying json.parse recieve error:

"uncaught syntaxerror: unexpected token f" 

the response looks like:

[{"src":"upload\/lessons\/963\/video\/176481500-m.webm","thumb_src":"upload\/lessons\/963\/slide\/thumb_0f515a62753626e1aaefdc7968e8103e.jpg"}] 

very strange thing that, similar code works nearby.. looks fine.. appreciate help, thanks.

you cannot json.parse() json, param must string :

json.parse('[{"src":"upload\/lessons\/963\/video\/176481500-m.webm","thumb_src":"upload\/lessons\/963\/slide\/thumb_0f515a62753626e1aaefdc7968e8103e.jpg"}]'); 

the error receive can reproduced :

json.parse([{"src":"upload\/lessons\/963\/video\/176481500-m.webm","thumb_src":"upload\/lessons\/963\/slide\/thumb_0f515a62753626e1aaefdc7968e8103e.jpg"}]); 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -