这是一个有点难以解释的问题,所以我给你展示一下。如果您看下面,您将看到有效的 JSON。
{
"data":{
"0":{
"action_id":"1",
"date":"2012-04-10 15:07:38",
"action_type":"1",
"action_text":"Some one got blamed!"
},
"1":{
"action_id":"2",
"date":"2012-04-10 16:18:05",
"action_type":"1",
"action_text":"Testing multiple items for AJAX"
},
"total":2,
"ajax_message":"Success",
"ajax_status":"0",
"success":"true"
}
}
但是对于正在使用的应用程序,它无法处理“0”:“1”,它只是希望它用逗号分隔。
我当前生成此代码的代码是:
while ($r = mysql_fetch_assoc($q)) {
$array[] = $r;
}
json_encode($array);
目前相当简单和原始的东西。但我想我可能必须为自己编写一个 json_encode 才能像这样打印它.....
任何帮助将不胜感激
注意:这是一个有效的表格(手写):
{
"data": [
{
"action_id": "1",
"date": "2012-04-10 15:07:38",
"action_type": "1",
"action_text": "Some one got blamed!",
"fb_id": "760775384"
},
{
"action_id": "2",
"date": "2012-04-10 16:18:05",
"action_type": "1",
"action_text": "Testing multiple items for AJAX",
"fb_id": "760775384"
}
],
"total": 2,
"ajax_message": "Success",
"ajax_status": "0",
"success": "true"
}