Я использую структуру Slim для REST API. Мой tasks
маршрут определяется как:Получить данные массива json
$app->get('/tasks', 'authenticate', function() {
global $user_id;
$response = array();
$items = array();
$db = new DbHandler();
$result = $db->getAllUserTasks($user_id);
if ($result != NULL) {
foreach ($result as $rez) {
$response["error"] = false;
$response["id"] = $rez["id"];
$response["task"] = $rez["task"];
$response["status"] = $rez["status"];
$response["createdAt"] = $rez["created_at"];
$items[] = $response;
}
echoRespnse(200, $items);
} else {
$response["error"] = true;
$response["message"] = "The requested resource doesn't exists";
echoRespnse(404, $response);
}
});
Я хочу, чтобы этот вид ответа JSon:
{
"error": false,
"tasks": [
{
"id": 1,
"task": "Complete test1",
"status": 0,
"createdAt": "2014-01-08 23:35:45"
},
{
"id": 2,
"task": "Complete test2",
"status": 0,
"createdAt": "2014-01-08 23:56:52"
}
]
}
Вместо этого, я получаю что-то вроде:
[1] 0: { error: false "2" task: "2" status: "2" createdAt: "2" }
Что случилось с моим маршрут?
Спасибо, но теперь я получаю неправильные данные, как это: '[1] 0: { ошибка: ложная задача: [8] 0: { ID: 11 } - 1: { задача: "hhhhhhhhh" } - 2: { статус: 0 } - 3: { createdAt: "2015-03-20 4:56:30" } - 4: { ID: 12 } - 5: { Задача: "hhhhhhhhhnnnnnnn" } - 6: { статус: 0 } - 7: { createdAt: "2015-03-20 4:57:50" } - - } ' – David
проверить меня сейчас ответить. –
же ошибка '[1] 0: { ошибка: ложная задача: [26] 0: { ID: 11 задача: "hhhhhhhhh" Статус: 0 createdAt:«2015-03-20 04: 56:30" } - 1: { ID: 12 задача: "hhhhhhhhhnnnnnnn" статус: 0 createdAt: "2015-03-20 4:57:50" } - 2: { ID: 13 Задача: "-7,643060" Статус: 0 createdAt: "2015-03-21 05:39:47" } ' – David