+ 2

Unexpected ':' when converting associative array to Jason using json_encode in php

I am trying to convert associative array to json using json_encode function and echoing it out and using jQuery Ajax to display in console . But it says unexpected ' : ' in the console. when iam setting data type:"json" it's working but not working in data type:"jsonp" . here are the images : error: https://drive.google.com/file/d/17fU_moYLhE1QpCySYGLw-tP40DtyseqL/view?usp=drivesdk php code: https://drive.google.com/file/d/1lFTJeYQdCavSLZ9G2sMTBl0v3AT0riJ8/view?usp=drivesdk

13th Mar 2018, 11:51 AM
S O U ✌ I K
S O U ✌ I K - avatar
1 Answer
+ 3
It's better to give people code in text form, rather than use screenshots, so they can import the code more easily into their system, to test to see if they get the same issue. Have you tried the Json validator to validate your Json output? https://jsonlint.com/ Your Json looks fine to me. Is it to do with the MIME type: https://www.sitepoint.com/community/t/json-php-unexpected-error/84995 "header('Content-type: application/json'); echo json_encode($data);"
2nd Apr 2018, 12:32 AM
Emma