dplece1882 2012-04-20 11:57
浏览 275

解析数据时出错org.json.JSONException:类型org.json.JSONObject $ 1的lat值为null无法转换为double

I am getting the following error with andoroid trying to return data from PHP

try {
    BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
    StringBuilder sb = new StringBuilder();
    String line = null;
    while ((line = reader.readLine()) != null) {
        sb.append(line + "
");
    }
    is.close();

    result=sb.toString();
} catch(Exception e) {
    Log.e("log_tag", "Error converting result "+e.toString());
}

//parse json data
try {
    JSONArray jArray = new JSONArray(result);

    //-----------------------------------------

    //----------------------------------------
    for(int i=0;i<jArray.length();i++) {
        JSONObject json_data = jArray.getJSONObject(i);
        map = new HashMap<String, String>();
        map.put("nomclt", (String) json_data.get("nomclt"));
        map.put("prenomclt", (String) json_data.get("prenomclt"));
        // map.put("adresse", (String) json_data.get("adresse"));
        //enfin on ajoute cette hashMap dans la arrayList
        listItem.add(map)

Script php

<?php
    header('Content-type: application/json');

    mysql_connect("localhost","root","");
    mysql_select_db("test");

    $sql=mysql_query("SELECT * FROM client");
    $output = array();
    while($row=mysql_fetch_array($sql))
        $output[]=$row;

    print(json_encode($output));

    mysql_close();
?>
  • 写回答

3条回答 默认 最新

  • douzhi1937 2012-04-20 12:00
    关注

    I don't know if it's the problem but json_encode() only works with UTF-8 values : http://php.net/json_encode

    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?