Reputation: 3335
I have fetched Google Analytics profiles from my account, and returned an JSON object to my view. But I want to convert this object.
[
{
Account A: {
xxxxxxxx: "All Web Site Data"
}
},
{
Account B: {
xxxxxxxx: "All Web Site Data"
}
}
]
to this
{
Account A: {
xxxxxxxx: "All Web Site Data"
}
},
{
Account B: {
xxxxxxxx: "All Web Site Data"
}
}
How can i do this using PHP.
Upvotes: 2
Views: 1685
Reputation: 12127
Your json object looking incorrect, try this way
<?php
$jsond = '[{ "AccountA": {"xxxxxxxx": "All Web Site Data"}},{"AccountB": {"xxxxxxxx": "All Web Site Data"}}]';
$arr = json_decode(trim($jsond));
//echo json_last_error_msg ();
print_r($arr[0]);
?>
Simply use [0]
index object
var json = json[0];
console.log(json);
var $json = $json[0];
var_dump($json);
Upvotes: 2
Reputation: 31749
Try with -
$json = (array) json_decode($yourJson);
var_dump($json);
Upvotes: 0