這已經讓我徹底難倒了:json_encode問題
print_r($json);
echo json_encode($json);
輸出:
Array
(
[query] => dia
[suggestions] => Array
(
[0] => Diana Johnson
[1] => Diane Abbott
)
)
{"query":"dia","suggestions":[null,null]}
這到底是哪裏錯了?
編輯只需添加到這個一般WTF-ERY,這裏的另一個示例:
Array
(
[query] => david
[suggestions] => Array
(
[0] => David Cameron
[1] => David Amess
[2] => David Anderson
[3] => David Blunkett
[4] => David Burrowes
)
)
{"query":"david","suggestions":["David Cameron",null,null,null,null]}
您是否100%肯定'$ json'中的所有內容都是有效的UTF-8? – Jon 2011-03-22 22:58:43
這一切都是從同一個數據庫的同一張表中拖出來的。有沒有理由不這樣做? – fredley 2011-03-22 23:00:01