PHP変数内に保存されているこのjsonから必要なデータを抽出するのに苦労しています。この種のデータ構造の専門家はまだいません...
誰かがそれを機能させる方法を知っているのだろうか。
結果をループしてから、各連絡先を読み取って 1. type=email の値 2. type=name の value->givenName (要素が存在する場合)
jsonでデコードされた値は次のとおりです
$aNative = json_decode($retval);
echo "lang: " . $aNative->query->lang . "<br>"; (works)
(when go deeper, fail to retrieve any value...)
echo "created: " . $aNative->results->contact[0]->created . "<br>";
foreach($aNative->$query->results as $contact)
{
echo $contact->id;
echo $contact->fields[0]->type;
if($contact->fields[0]->type=="email")
{
echo $contact->fields[0]->value;
}
}
完全なjson:
{
"query":{
"count":10,
"created":"2012-06-13T09:13:45Z",
"lang":"en-US",
"results":{
"contact":[
{
"created":"2006-10-29T04:32:07Z",
"updated":"2006-10-29T04:32:07Z",
"uri":"http://social.yahooapis.com/v1/user/BNQJOMYDQYLY2FZSMROV4QDA6MI/contact/14",
"isConnection":"false",
"id":"14",
"fields":{
"created":"2006-10-29T04:32:07Z",
"updated":"2006-10-29T04:32:07Z",
"uri":"http://social.yahooapis.com/v1/user/BNQJOMYDQYLY2FZSMROV4QDA6MI/contact/14/email/11",
"id":"11",
"type":"email",
"value":"angBB@gmail.com",
"editedBy":"OWNER"
}
},
{
"created":"2006-10-29T04:32:07Z",
"updated":"2006-10-29T04:32:07Z",
"uri":"http://social.yahooapis.com/v1/user/MNQJOMYDQYLY2FZSMROV4QDA6MI/contact/12",
"isConnection":"false",
"id":"12",
"fields":[
{
"created":"2006-10-29T04:32:07Z",
"updated":"2006-10-29T04:32:07Z",
"uri":"http://social.yahooapis.com/v1/user/MNQJOMYDQYLY2FZSMROV4QDA6MI/contact/12/email/6",
"id":"6",
"type":"email",
"value":"jaq@lifemastr.com",
"editedBy":"OWNER"
},
{
"created":"2006-10-29T04:32:07Z",
"updated":"2006-10-29T04:32:07Z",
"uri":"http://social.yahooapis.com/v1/user/MNQJOMYDQYLY2FZSMROV4QDA6MI/contact/12/name/5",
"id":"5",
"type":"name",
"value":{
"givenName":"'Jaq'",
"middleName":null,
"familyName":null,
"prefix":null,
"suffix":null,
"givenNameSound":null,
"familyNameSound":null
},
"editedBy":"OWNER"
}
]
}
]
}
}
}