- json_decode: documentation ( source)
- json_encode: documentation ( source)
<?php
$jsonStr = '{"return_data": {
"friend_info": [
{
"desc": "name",
"value": "Ken"
},
{
"desc": "profile_pic",
"value": "http://aaa.caa/1234569/picture?type=large"
}
]
}}';
$json = json_decode($jsonStr, true);
$obj = new stdClass;
foreach ($json["return_data"]["friend_info"] as $item)
$obj->{$item["desc"]} = $item["value"];
$json["return_data"]["friend_info"] = $obj;
$jsonStr = json_encode($json);
echo $jsonStr;