[英]Is it possible to print the value of Key from the (key-value)pair of json object in laravel
如何从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"
}
},
如何显示以上数据中的“输入”?
将JSON
放入变量中。 例如 $jsonVariable
。
json_decode($jsonVariable)->pricing->in
首先,我认为您的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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.