-1

jqueryを使用してこのjsonを解析するにはどうすればよいですか? 私はjsonが初めてなので、これを行うことができません。以下の json から名前 (imran) とフォロワー名 (ali & noor) を解析する必要があります。

{"data":[{"data":{"name":"Imran","email":"imran@example.com","phone":"+9221-000000","location":"khi, pk","userid":"1114","date":"2012 年 7 月 7 日午前 5 時 39 分","privacy":"0","type":"0","last_updated":"9 月 11 日、2012 年、午前 8:59","images_count":0,"component":"profile"},"0":null,"1":null,"2":[{"following":{"frienduserid" :"1353","name":"Haider"}},{"following":{"frienduserid":"1148","name":"Ali"}}],"3":[{"フォロワー": {"ユーザーID":"1148","名前":"アリ"}},{"follower":{"userid":"1054","name":"noor"}}]}]}

4

2 に答える 2

2

非常に単純な PHP の例:

<php?

// Convert JSON to an associative array
$arr = json_decode('{"data":[{"data":{"name":"Imran","email":"imran@example.com","phone":"+9221-000000","location":"khi,pk","userid":"1114","date":"July 7, 2012, 5:39 am","privacy":"0","type":"0","last_updated":"September 11, 2012, 8:59 am","images_count":0,"component":"profile"},"0":null,"1":null,"2":[{"following":{"frienduserid":"1353","name":"Haider"}},{"following":{"frienduserid":"1148","name":"Ali"}}],"3":[{"follower":{"userid":"1148","name":"Ali"}},{"follower":{"userid":"1054","name":"noor"}}]}]}', true);

// Dump the element containing the name
var_dump($arr['data'][0]['data']['name']);

// Loop through followers and dump each follower's name
foreach ($arr['data'][0][3] as $item)
{
    var_dump($item['follower']['name']);
}
?>
于 2012-09-24T10:04:50.897 に答える
0

あなたのjson構造はかなり乱雑に見えます...おそらくそれを見直す必要があります。ただし、次の方法で目的のデータにアクセスできるはずだと思います。

jsonObject = JSON.Parse(yourJSONString) //This will create your jsonObject
jsonObject.data[0].data.name --> should hold the name
jsonObject.data[0].data["2"][2].follower.name --> should hold de name of the first follower. 
于 2012-09-24T10:43:14.780 に答える