-2

使用 true 选项,它工作正常。

对不起,谢谢你们。

==============================================

我用这段代码将 php 数组编码为 json

$rows = array();
if ($result = $mysqli->query($query)) {
    while ($row = $result->fetch_assoc()) {
        $rows[] = $row;
    }
    echo json_encode($rows);
    /* free result set */
    $result->free();
}

结束解码

$array = json_decode($server_output)

$server_output 是这样的

[{"userid":"96679","userinfor":"xxxxxxxxx","userlocation":"CA"}]
[{"userid":"153795","userinfor":"xxxxxxxxx","userlocation":"CA"}]
[{"userid":"131878","userinfor":"xxxxxxxxx","userlocation":"CA"}]

但是,$array 是 NULL :(

提前感谢,

4

1 回答 1

0

这不是有效的 json 一起:

[{"userid":"96679","userinfor":"xxxxxxxxx","userlocation":"CA"}]
[{"userid":"153795","userinfor":"xxxxxxxxx","userlocation":"CA"}]
[{"userid":"131878","userinfor":"xxxxxxxxx","userlocation":"CA"}]

虽然,这部分是有效的:

[{"userid":"96679","userinfor":"xxxxxxxxx","userlocation":"CA"}]

或其中任何一个单独

$json = '[{"userid":"96679","userinfor":"xxxxxxxxx","userlocation":"CA"}]';
print_r(json_decode($json, true));

输出:

Array
(
    [0] => Array
        (
            [userid] => 96679
            [userinfor] => xxxxxxxxx
            [userlocation] => CA
        )

)

所有数据的有效格式如下:

[
    {
        "userid": "96679",
        "userinfor": "xxxxxxxxx",
        "userlocation": "CA"
    },
    {
        "userid": "153795",
        "userinfor": "xxxxxxxxx",
        "userlocation": "CA"
    },
    {
        "userid": "131878",
        "userinfor": "xxxxxxxxx",
        "userlocation": "CA"
    }
]
于 2013-08-01T01:28:00.720 回答