我有一些JSON的問題。我如何使我的陣列"$notify_id"
成爲JSON數組?因爲當我運行我的推網絡應用程序時,它會回答我「Field 'data' must be a JSON array: {"registration_id":["14096543677114293"]}
」。如何讓我的數組成爲JSON數組?
請幫
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;
}
'return json_encode($ notify_id);' – Steve 2014-09-02 10:56:52
閱讀['json_encode'](http://php.net/manual/en/function.json-encode.php) – 2014-09-02 11:02:09
根據你的例子JSON頂部,你需要'echo json_encode(array('registration_id'=> $ notify_id));' – 2014-09-02 11:05:23