[英]how to read a php json decoded array
I get the following string when I use $JSON = var_dump(json_decode($MyJSON, true));
当我使用
$JSON = var_dump(json_decode($MyJSON, true));
时,得到以下字符串$JSON = var_dump(json_decode($MyJSON, true));
If I echo $JSON:- 如果我回显$ JSON:-
array(1) {
["test"]=> array(2) {
[0]=> array(3) {
["subject"]=> array(2) {
["type"]=> string(10) "blank node" ["val"]=> string(4) "_:b0"
}
["predicate"]=> array(2) {
["type"]=> string(3) "IRI" ["val"]=> string(47) "http://www.w3.org/1999/02/22-rdf-syntax-ns#type"
}
["object"]=> array(2) {
["type"]=> string(3) "IRI" ["val"]=> string(25) "http://schema.org/WebPage"
}
}
[1]=> array(3) {
["subject"]=> array(2) {
["type"]=> string(10) "blank node" ["val"]=> string(4) "_:b0"
}
["predicate"]=> array(2) {
["type"]=> string(3) "IRI" ["val"]=> string(28) "http://schema.org/breadcrumb"
}
["object"]=> array(2) {
["type"]=> string(10) "blank node" ["val"]=> string(4) "_:b1"
}
}
}
}
what if I want to echo $JSON->test[0]->predicate->val
what is the right syntax? 如果我想
echo $JSON->test[0]->predicate->val
怎么办?正确的语法是什么? Sorry I am a beginner. 对不起,我是初学者。 It would be a big help.
这将是一个很大的帮助。 Thanks in advance.
提前致谢。
Remove var_dump 删除var_dump
$JSON = var_dump(json_decode($MyJSON, true));
So $JSON becomes 所以$ JSON变成
$JSON = json_decode($MyJSON, true);
You will then be able to access the variable required via 然后,您将可以通过访问所需的变量
$JSON['test'][0]['predicate']['val'];
Did you already try to do json_decode($MyJson)
without true as second parameter? 您是否已经尝试在没有true的情况下执行
json_decode($MyJson)
作为第二个参数? This will return a STD object which should resemble the way you want to access the json object. 这将返回一个STD对象,该对象应类似于您要访问json对象的方式。 See the PHP documentation for more info (second parameter $assoc=true means that it will be converted to an associative array): json_decode
有关更多信息,请参见PHP文档(第二个参数$ assoc = true表示它将被转换为关联数组): json_decode
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.