dozpv84422 2017-05-02 15:10
浏览 56
已采纳

PHP数组没有使用json_encode转换为JSON [duplicate]

This question already has an answer here:

I am trying to convert my $response array to JSON but it is not converting. I tried to echo the values in the array to be sure that it is not null.

    if($row['count(*)']>0)
    {
        $sql="select * from guide_city_detail where CITY='$place'";
        $result = $conn->query($sql);
        $row = $result1->fetch_assoc();
        $row = array_map('utf8_encode', $row);
        $response['status']=1;
        $response['city']=$row['CITY'];
        $response['state']=$row['STATE'];
        $response['country']=$row['COUNTRY'];
        $response['heads']=$row['HEADS'];
        $response['col1']=$row['COL1'];
        $response['col2']=$row['COL2'];
        $response['col3']=$row['COL3'];
        $response['col4']=$row['COL4'];
        $response['col5']=$row['COL5'];
        $response['col6']=$row['COL6'];
        $response['col7']=$row['COL7'];
        $response['col8']=$row['COL8'];
        $response['col9']=$row['COL9'];
        //echo $response['country'];
    }
    else
    {
        $response['status']=0;// save the entry for future references
        $output = shell_exec("java -cp \".;D:/letsgo/mysql.jar;D:/letsgo/jsoup.jar;\" GeneralPopulate $place 2>&1");
        //echo "$output";
    }
    $res=json_encode($response);
    echo $res;
}
</div>
  • 写回答

1条回答 默认 最新

  • dqiaw48488 2017-05-02 15:17
    关注

    If json_last_error gives you the JSON_ERROR_UTF8 error code (5), then you will have to encode your datas in UTF-8 :

    Need to convert final array to utf-8.

    <?php
    
    $response = array_map('utf8_encode', $response);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 服务端控制goose报文控制块的发布问题
  • ¥15 学习指导与未来导向啊
  • ¥15 求多普勒频移瞬时表达式
  • ¥15 如果要做一个老年人平板有哪些需求
  • ¥15 k8s生产配置推荐配置及部署方案
  • ¥15 matlab提取运动物体的坐标
  • ¥15 人大金仓下载,有人知道怎么解决吗
  • ¥15 一个小问题,本人刚入门,哪位可以help
  • ¥30 python安卓开发
  • ¥15 使用R语言GD包一直不出结果