我对php很陌生,我的措辞是如何返回JSON数据类型的关联数组?下面是我的php代码:
$JSON = file_get_contents($url);
// echo the JSON (you can echo this to JavaScript to use it there)
//echo $JSON;
// You can decode it to process it in PHP
$data = json_decode($JSON,true);
var_dump($data);当我将数据转储到屏幕上时,这里有一个数据片段:
array(2) {
["product"] => array(1) {
[0]=> array(7) {
["styles"]=> array(13) {
[0]=> array(7) {
["price"]=> string(6) "$64.95"
["productUrl"]=> string(46) "http://www.zappos.com/product/7515478/color/25"
["percentOff"]=> string(2) "0%"
["styleId"]=> string(7) "1788226"
["imageUrl"]=> string(65) "http://www.zappos.com/images/z/1/7/8/8/2/2/1788226-p-DETAILED.jpg"
["color"]=> string(6) "Almond"
["originalPrice"]=> string(6) "$64.95"
}现在,我将如何访问第一个数组元素?我试过:
echo $data[0][0]['orignalPrice'];但它不起作用。有人能帮忙吗?另外,在mac上是否有一个适用于php的良好调试器?感谢你的帮助。
发布于 2014-02-14 23:48:26
试试那个$data['product'][0]['styles'][0]['originalPrice']
还建议您查看文档,以了解有关列阵的更多信息。
https://stackoverflow.com/questions/21791406
复制相似问题