如何从laravel中的json对象打印'key'值。
json数组:
"pricing": {
"in": {
"categories": [
"ccTLD",
"Geography"
],
"addons": {
"dns": true,
"email": true,
"idprotect": true
},
"group": "",
"register": {
"1": "704.39"
},
"transfer": {
"1": "704.39"
},
"renew": {
"1": "704.39"
}
},
如何从上述数据中显示“in”?
答案 0 :(得分:0)
将JSON
放入变量中。防爆。 $jsonVariable
。
json_decode($jsonVariable)->pricing->in
答案 1 :(得分:0)
首先,我认为你的json中存在一些错误,这是我用两种方式实现相同的功能
public function demo()
{
$json_array = '
{
"pricing": {
"in": {
"categories": [
"ccTLD",
"Geography"
],
"addons": {
"dns": true,
"email": true,
"idprotect": true
},
"group": "",
"register": {
"1": "704.39"
},
"transfer": {
"1": "704.39"
},
"renew": {
"1": "704.39"
}
}
}
}
';
echo "<pre>";
print_r(json_decode($json_array)->pricing->in);
$asso_array = json_decode($json_array, true);
print_r($asso_array["pricing"]["in"]);
exit;
}