android中的json解析
我从一个php主机得到一个json响应 {“uid”:“0”} 我想从中检索0(即uid值) 我试着找回它,但有例外 这是我的密码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 {
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");
}