将 Yahoo Contact API 集成到我的网站后,我开始获取用户联系人列表作为 Yahoo JSON 响应联系人对象。
以下是响应格式:
{"contacts":{"start":0,"count":5,"total":110,"contact":[{"isConnection":false,"id":16777250,"fields":[{"id":16777292,"type":"yahooid","value":"ahmed_love7353","editedBy":"OWNER","categories":[]},{"id":16777291,"type":"name","value":{"givenName":"ahmed","middleName":"","familyName":"_love","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","categories":[]}]},{"isConnection":false,"id":52,"fields":[{"id":124,"type":"email","value":"15688708283341592078@mail.orkut.com","editedBy":"OWNER","categories":[]}]},{"isConnection":false,"id":16777271,"fields":[{"id":16777343,"type":"email","value":"abcdall4u@gmail.com","editedBy":"OWNER","categories":[]}]},{"isConnection":false,"id":31,"fields":[{"id":69,"type":"yahooid","value":"supriya_9392","editedBy":"OWNER","categories":[]},{"id":70,"type":"name","value":{"givenName":"Supriya","middleName":"","familyName":"Agarwal","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","categories":[]}]},{"isConnection":false,"id":23,"fields":[{"id":45,"type":"phone","value":"09470657255","editedBy":"OWNER","flags":["MOBILE"],"categories":[]},{"id":44,"type":"name","value":{"givenName":"akhilesh","middleName":"brother()","familyName":"","prefix":"","suffix":"","givenNameSound":"","familyNameSound":""},"editedBy":"OWNER","categories":[]}]}]}}
问题:
无法从上述代码中读取(获取)givenName、familyName 和电子邮件。
试过:
使用json_decode();
过,但我再次无法阅读相同的内容。
以下是解码格式:
stdClass Object ( [contacts] => stdClass Object ( [start] => 0 [count] => 5 [total] => 110 [contact] => Array ( [0] => stdClass Object ( [isConnection] => [id] => 16777250 [fields] => Array ( [0] => stdClass Object ( [id] => 16777292 [type] => yahooid [value] => ahmed_love7353 [editedBy] => OWNER [categories] => Array ( ) ) [1] => stdClass Object ( [id] => 16777291 [type] => name [value] => stdClass Object ( [givenName] => ahmed [middleName] => [familyName] => _love [prefix] => [suffix] => [givenNameSound] => [familyNameSound] => ) [editedBy] => OWNER [categories] => Array ( ) ) ) ) [1] => stdClass Object ( [isConnection] => [id] => 52 [fields] => Array ( [0] => stdClass Object ( [id] => 124 [type] => email [value] => 15688708283341592078@mail.orkut.com [editedBy] => OWNER [categories] => Array ( ) ) ) ) [2] => stdClass Object ( [isConnection] => [id] => 16777271 [fields] => Array ( [0] => stdClass Object ( [id] => 16777343 [type] => email [value] => abcdall4u@gmail.com [editedBy] => OWNER [categories] => Array ( ) ) ) ) [3] => stdClass Object ( [isConnection] => [id] => 31 [fields] => Array ( [0] => stdClass Object ( [id] => 69 [type] => yahooid [value] => supriya_9392 [editedBy] => OWNER [categories] => Array ( ) ) [1] => stdClass Object ( [id] => 70 [type] => name [value] => stdClass Object ( [givenName] => Supriya [middleName] => [familyName] => Agarwal [prefix] => [suffix] => [givenNameSound] => [familyNameSound] => ) [editedBy] => OWNER [categories] => Array ( ) ) ) ) [4] => stdClass Object ( [isConnection] => [id] => 23 [fields] => Array ( [0] => stdClass Object ( [id] => 45 [type] => phone [value] => 09470657255 [editedBy] => OWNER [flags] => Array ( [0] => MOBILE ) [categories] => Array ( ) ) [1] => stdClass Object ( [id] => 44 [type] => name [value] => stdClass Object ( [givenName] => akhilesh [middleName] => brother() [familyName] => [prefix] => [suffix] => [givenNameSound] => [familyNameSound] => ) [editedBy] => OWNER [categories] => Array ( ) ) ) ) ) ) )
问题:
如何以简单的方式阅读 givenName、familyName 和 email?
使其更具可读性的最佳方法是什么?
注意:我是 JSON 新手。