解析数据 org.json.JSONException 时出错:在 org.json.JSONObject$1 类型的纬


Error parsing data org.json.JSONException: Value null at lat of type org.json.JSONObject$1 cannot be converted to double

我在尝试从 PHP 返回数据时收到以下错误 andoroid

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 + "'n");
    }
    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)

脚本 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();
?>
我不知道

这是否是问题所在,但json_encode()仅适用于UTF-8值:http://php.net/json_encode

这可能是jSON中的一个问题。通过粘贴 php 文件的 json 或 url,使用 JSONLint 检查 php 返回的 json。

谁行导致 Android 端提示异常? 键入以下内容以解析 JSONObject 字符串:

map = new HashMap<String, Object>(); 

希望它有效!

相关文章: