【发布时间】:2016-08-14 16:04:42
【问题描述】:
我是 JavaScript 和 PHP 的新手。我已经阅读了多个堆栈以获得答案,但我的 JSON 字符串有点不同。如果你问我,其实很简单。
字符串如下:
[[{"height":"444","width":"444","picture":"/image/data/122.jpg","x":0,"y":0,"currentheight":"444"},{"height":"444","width":"444","picture":"/image/data/122.jpg","y":"444","x":0,"currentheight":888},{"height":"223","width":"444","picture":"/image/data/122.jpg","y":888,"x":0,"currentheight":1111}],[{"height":"223","width":"444","picture":"/image/data/122.jpg","y":0,"x":444,"currentheight":"223"},{"height":"223","width":"444","picture":"/image/data/122.jpg","y":"223","x":444,"currentheight":446}]
现在我正在尝试使用json_decode($jsonstring, true) 对其进行解码,但是当我通过它的索引调用它时它只是没有得到一个值。一旦我尝试使用echo $jsonstring[0] 获取数据,我就会得到[ 作为结果。 $jsonstring[0]['width'] 甚至不返回任何内容。
是我说错了还是别的什么?
【问题讨论】:
-
字符串末尾缺少关闭
]? -
你有一个矩阵/表格;数组数组。首先你需要解码 json
$table = json_decode($jsonstring, true)然后你可以得到一个对象$row = $table[0];$item = $row[0];现在你可以获取像widthecho 'width: ' . $item['width'];或var_dump($item);这样的属性。您需要了解您正在处理的数据结构。
标签: javascript php json multidimensional-array