[英]How do I parse this kind of json string in PHP, since json_decode not working?
I read a data from URL & I get the response in below json format: 我从URL读取数据,并以以下json格式获取响应:
'"{\r\n \"data\": \"\",\r\n \"error\": \".\",\r\n \"success\": \"\"\r\n}"'
Since after using json_decode($aboveStr, true); 由于使用json_decode($ aboveStr,true); it outputs the following string format:
它输出以下字符串格式:
{"data": "","error": "","success": ""}
I want the output in array. 我想要数组中的输出。
出于某种原因,你输入的字符串已经被编码成JSON的两倍,因此你需要调用json_decode()
两次:
$array = json_decode(json_decode($aboveStr), true);
You need to decode your string twice by using json_decode
twice. 您需要使用两次
json_decode
对字符串进行两次解码。 Try: 尝试:
print_r(json_decode(json_decode($aboveStr), TRUE));
It prints 它打印
Array ( [data] => [error] => . [success] => )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.