我有几个json编码的对象,我想将它们写入json文件。数据来自Facebook。 例如,如果我
$myfile="testson.json";
$fileout=fopen($myfile,'w') or die("Fatal: Can't write to JSON file");
$friends = idx($facebook->api('/me/friends?limit=5000'), 'data', array());//gather data from facebook
fwrite($fileout,json_encode($friends));
我得到这样的东西: [{“name”:“xyz”,“id”:“2342342”},{其他条目一样}]
或者,就像喜欢的那样:
[{"category":"Musician\/band","name":"Jack Savoretti","id":"216730015024772","created_time":"2013-03-14T13:38:27+0000"},{other entries alike}]
现在我想做的是在某些类别下列出每一个。例如
["Likes":[{"category":"Musician\/band","name":"Jack Savoretti","id":"216730015024772","created_time":"2013-03-14T13:38:27+0000"},
{other entries alike}],
"friends":[{"name":"xyz","id":"2342342"},{other entries alike}]]
我该怎么做?
我正在使用php json_encode
。