개발! 딱 깔끔하고 센스있게!

php JSONu encode 일하지 않습니다. 본문

개발 스크랩 메모/PHP

php JSONu encode 일하지 않습니다.

렉사이 2020. 12. 19. 02:37

나는 여기서 이 JSON 에게 출력을 받고 싶다.

불행히도 jsonu encode () 함수는 이 형식으로 구성되지 않는다는 것이다.

조금도 돌아오지 않는다.

이것은 나의 비밀번호다

$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); 

나는 원인을 찾을 수 없다.

누군가가 나를 도와 해결 방법을 찾아주세요.

편집: 죄송합니다.

여기는 출력-

예상했던 JSON 출력-

{ "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 } 

나는 JSON 의 출력은 전혀 없다.

그러나 이는 디지털 인쇄 결과다.

 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 ) 

대답

다행히 @awiebe 덕분에 확실한 잘못을 발견했습니다.

네, 그것도 좋아요.

Malformed UTF-8 characters, possibly incorrectly encoded

감사합니다.

저는 다른 문제에서 해결책을 찾았습니다.

"형식이 부정확한 UTF-8 문자, 인코딩이 잘못될 수도 있어요".

Comments