[英]Getting multidimensional array from json_decode
How do I access $result['products'] from this JSON response? 如何从此JSON响应访问$ result ['products']?
{"503380":{"response_code":"100","click_id":"10215bdfce7c","product_qty_30":"3","products[0][product_id]":"30","products[0][sku]":"ACMEROCKET","products[0][price]":"32.66"}}
$result = json_decode($result, 1);
Then when I do 那我做的时候
print_r($result['products]);
I just get 我刚得到
Notice: Undefined index: products
But when I do 但是当我这样做
print_r($result);
I get 我懂了
Array
(
[503380] => Array
(
[response_code] => 100
[click_id] => 10215bdfce7c
[product_qty_30] => 3
[products[0][product_id]] => 30
[products[0][sku]] => ACMEROCKET
[products[0][price]] => 32.66
)
)
I noticed there were two ending brackets (]) after each products element but how do I make them accessible through 我注意到每个产品元素后面都有两个结尾括号(),但是如何通过以下方式访问它们
$result['products']
? ?
谢谢大家。事实证明,这只是错误地传递了JSON。
It is incorrect JSON, but if you realy need you can try something like this: 这是不正确的JSON,但如果您确实需要,可以尝试执行以下操作:
$result = json_decode($json, true);
foreach($result[503380] as $key=>$value) {
@eval("$" . $key . " = \"" . $value . "\";");
}
var_dump($products);
But it is very BAD PRACTICE! 但这是非常糟糕的做法! Because in json can be malicious code that is executed on your server. 因为在json中可能是在服务器上执行的恶意代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.