This is my JSON
$result=[{CFirst: "test3"},{CLast: "test3"},{CEmail: "test2@gmail.com"}]
I am getting this as a result of an API request. I guessed it was json, so tried to json_decode()
, but it didn't work and json_last_error()
returned code 4.
Thanks for help
Your JSON is in bad format , you need to enclose them under double quotes like this.
[{"CFirst": "test3"},{"CLast": "test3"},{"CEmail": "test2@gmail.com"}]
The CFirst,CLast
& CEmail
have been wrapped around double quotes for your information.
<?php
$json='[{"CFirst": "test3"},{"CLast": "test3"},{"CEmail": "test2@gmail.com"}]';
print_r(json_decode($json,true));
EDIT :
<?php
$result='[{CFirst: "test3"},{CLast: "test3"},{CEmail: "test2@gmail.com"}]';
$result=str_replace(array('{',':'),array('{"','":'),$result); //<--- Add this
print_r(json_decode($result,true));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.