Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android中的json解析_Android_Json - Fatal编程技术网

android中的json解析

android中的json解析,android,json,Android,Json,我从一个php主机得到一个json响应 {“uid”:“0”} 我想从中检索0(即uid值) 我试着找回它,但有例外 这是我的密码 HttpEntity entity = response.getEntity(); } catch(Exception e) { System.out.println("Exception : " + e.getMessage()); } finally { if (conn != null) { try {

我从一个php主机得到一个json响应

{“uid”:“0”}

我想从中检索0(即uid值)

我试着找回它,但有例外

这是我的密码

    HttpEntity entity = response.getEntity();

} catch(Exception e) {
    System.out.println("Exception : " + e.getMessage());
}
finally {
    if (conn != null) {
        try {  
            conn.close ();
        }
        catch (Exception e) { e.printStackTrace(); }  
    }
}

//convert response to string
/*
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) {
    System.out.println("Exception : " + e.getMessage());
}
try
{
    ??????????????????????????
} catch(Exception e) { e.printStackTrace(); }
简单使用


使用可使此操作非常简单

Hi。这解决了你的问题吗?您需要传递Web服务的结果来代替“src”。如果我想发送我朋友的姓名,我将姓名存储在一个数组中,但json_编码方法不适用于此数组,该怎么办
JSONObject obj = new JSONObject(src);
if (obj.has("uid")){
   String uid = obj.getString("uid");
}