我正在尝试将gcm发送给数据库中的前10个用户。

尝试执行此操作时出现以下错误:


  “ registration_ids”字段不是JSON数组


下面是我获取gcm_id的函数

 function getAllRegIds() {
    $conn = new mysqli('localhost', 'root', 'android', 'android');

    if ($conn -> connect_error) {
        die("Connection failed: ".$conn->connect_error);
    }

    $queryString = "select gcm_id FROM user";

    $results = mysqli_query($conn, $queryString);

    $regids = array();
    foreach($results as $row) {
        $regids[]=$row['gcm_id'];
    }
    return regids;

}

最佳答案

尝试使用array_push:

function getAllRegIds() {
    $conn = new mysqli('localhost', 'root', 'android', 'android');

    if ($conn -> connect_error) {
        die("Connection failed: ".$conn->connect_error);
    }

    $queryString = "select gcm_id FROM user";

    $results = mysqli_query($conn, $queryString);

    $regids = array();
    foreach($results as $row) {
        array_push($regids, $row['gcm_id']);
    }
    return regids;

}

10-07 15:32