0

我想解析这个 JSON:

{
   "date":[
      "dia_29_06_13"
   ],
   "jsonList":{
      "__type":"File",
      "name":"d138af3c-4da0-4ab9-b3ff-0ac09a352fd8-lista.json",
   "localName":[
      "Patropi"
   ],
   "pspReference":"8513723597141689",
   "qrcode":"KWX35ERoNJ",
   "status":"true",
   "valor":127,
   "createdAt":"2013-06-27T19:01:46.830Z",
   "updatedAt":"2013-06-27T19:01:57.830Z",
   "objectId":"fcXMwYaDMQ",
   "ACL":{
      "*":{
         "write":true,
         "read":true
      },
      "KWX35ERoNJ":{
         "write":true,
         "read":true
      }
   }
}

但它总是给我这个错误:

date: 0: => dia_29_06_13
Catchable fatal error: Object of class stdClass could not be converted to string in /home/storage/a/1c/6e/semhora/public_html/payment/temp3.php on line 42

我正在使用这段代码:

$response = curl_exec($rest);

        $jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($response)),
    RecursiveIteratorIterator::SELF_FIRST);

foreach ($jsonIterator as $key => $val) {
    if(is_array($val)) {
        echo "$key:\n";
    } else {
        echo "$key: => $val";

    }
}
4

2 回答 2

1

一旦您期望嵌套项是数组 - 您需要将其解析为数组:

json_decode($response, true)

当第二个参数设置为true- 时,JSON 字符串将被解析为数组,而不是stdClass

于 2013-06-27T23:24:42.767 回答
0

您在上面发布的 JSON 无效。

在JSON Lint上检查它。

您打开的花括号比关闭的多一个花括号。

于 2013-06-27T23:27:40.913 回答