如何使我的数组成为JSON数组?

I have some problem with JSON. How can I make my array "$notify_id" a JSON array? Cause when I run my push web application it will answer me "Field 'data' must be a JSON array: {"registration_id":["14096543677114293"]} ".

Please help

   function insertNotificationStartTime($registration_id) {
        $timestamp = time();
        $start_notify = date("Y-m-d H:i:s",$timestamp);
        for ($i = 0; $i < count($registration_id); $i++) {
            $random = rand(1, 10000000);
            $query = "INSERT INTO notify (id,registration_id,start_notify) VALUES ('" .$timestamp.$random. "','" .$registration_id[$i]. "','" .$start_notify. "')";
            $result = mysql_query($query);
            if (!$result) {
                die('Invalid query: ' . mysql_error());
            }
            $notify_id[] = $timestamp.$random;
        }
        return $notify_id;
    }

you have to send Json header

header('Content-Type: application/json');
echo json_encode($notify_id);

Use

json_encode($notify_id);

If you get an error, Verify that the output is valid json at http://jsonlint.com.

According to your code the function is returning an array, and you have to pass to json_encode the result of this function.

$result = insertNotificationStartTime($registration_id);
header('Content-Type: application/json');
echo json_encode($result);

Please have a look on json_encode function

simply add

echo json_encode($notify_id);

at end of your code this function print array of your data..in your browser u must have json viewer extension so u can view your json data as array..

use this link

[1]: http://jsonlint.com/

put your code page link in that box check whether your json program is right or wrong

Script for backward-compatibility: https://github.com/douglascrockford/JSON-js/blob/master/json2.js

And call:

var myJsonString = JSON.stringify(yourArray);

Note: The JSON object is now part of most modern web browsers (IE 8 & above). See caniuse for full listing.