How to print the 'key' value from the json object in laravel.
The 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"
}
},
How to display "in" from the above data?
Put JSON
in a variable. Ex. $jsonVariable
.
json_decode($jsonVariable)->pricing->in
First of all i think there is some mistake in your json here is my funtion with two ways of achiving the same thing
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;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.