php json encode失败,JavaScript-PHP JSON_encode无法正常工作

我想从this获取this JSON输出.不幸的是json_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输出.但是这是数组的print_r结果.

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

标签:javascript,php,json,api

来源: https://codeday.me/bug/20191011/1893375.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值