Ich möchte this JSON-Ausgabe von this erhalten. Leider wird die json_encode() -Funktion das Array nicht in dieses Format codieren. Es ist überhaupt nichts zurück. Hier ist mein Code.php JSON_encode funktioniert nicht
$output = array(
'responseData' => array(),
'responseDetails' => null,
'responseStatus' => 200
);
$x = 0;
while ($row = mysqli_fetch_assoc($result)) {
foreach ($row as $k => $v) {
$output['responseData']['result'][$x][$k] = $v;
}
$x++;
}
print_r($output);
header('Content-Type: application/json');
echo json_encode($output , JSON_FORCE_OBJECT);
Ich kann den Grund nicht finden. jemand bitte helfen Sie mir, die Lösung zu finden.
Bearbeiten: Sorry. Hier Ausgänge -
Expected JSON Ausgabe -
{
"responseData": {
"results": [{
"qid": 1,
"qtitle": "When do we finish this project ?",
"qimage_url": "http://www.wearesliit.com/example.png",
"user": "samith",
"date": "2016-01-01T02:15:12.356Z",
"type": 1,
"category": 5,
"tags": ["common_senese", "truth", "bazsa_awsanna"],
"note": "Sample quetion"
}, {}, {}]
},
"responseDetails": null,
"responseStatus": 200 }
Ich habe keine JSON Ausgabe überhaupt bekommen. aber hier ist das print_r-Ergebnis des Arrays.
Array(
[responseData] => Array
(
[result] => Array
(
[0] => Array
(
[question_ID] => 1
[question_Title] => Which shape does not belong with the other three shapes?
[question_Image_URL] => http://www.wearesliit.com/images/quiz/questions/1.jpg
[quetion_Note] => Easy IQ question.
[category_ID] => 7
[username] => samith
[added] => 2017-01-29 21:50:52
)
[1] => Array
(
[question_ID] => 2
[question_Title] => Tim earns $10 per hour at his job. When he gets paid on Friday, he is paid for 40 hours of work. He then goes out and spends 10% of his earnings on entertainment that weekend. How much money is he left with on Monday?
[question_Image_URL] =>
[quetion_Note] => Easy IQ question.
[category_ID] => 7
[username] => samith
[added] => 2017-01-29 21:50:52
)
)
)
[responseDetails] =>
[responseStatus] => 200)
Was JSON Ausgabe von was? Denken Sie daran, es in Ihre Frage zu integrieren? – Kaylined
@Anant der zweite Link es nur, denke ich. –
Da es in Ihrem Code ist, zeigen Sie das Ergebnis von 'print_r ($ output);'. – AbraCadaver