我試着去用PHP編碼功能來創建此:JSON編碼問題
{
"foo": [
{
"bar": "111"
}
]
}
但所有我可以與一些PHP數組和JSON編碼管理是這樣的:
{
"foo": [
"{
\"bar\":184530"
}"
]
}
顯然我不t希望將對象當作字符串而不是對象,因此不用引號。
這裏是我的PHP:
$stmt->execute();
$stmt->bind_result($bar);
while ($stmt->fetch()) {
$activity_array = array("bar" => $bar);
$activity_json = json_encode($activity_array);
$json_array[] = $activity_json;
}
$json = json_encode($json_array);
echo '{ "foo": ' .$json .'}';
就是這樣,非常感謝!還有:$ json_array [] = $ activity_array; – MaikelS 2012-01-12 14:57:03
'json_encode'返回一個字符串,所以你的「JSON位」只是一個字符串。你只是編碼一個字符串數組。 – 2012-01-12 14:57:21