在intentservice中解析从SSM收到的json字符串
String result=null,re="";
JSONObject jsonObject = null;
try{
result = httpURLConnection.getResponseMessage();
bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
}catch(IOException h)
{
intent1.putExtra("registerstate","httpURLConnection.getResponseMessage();失败");
}
String line;
try{
while((line=bufferedReader.readLine())!=null)
{
re+=line;
}
}catch(IOException e){
intent1.putExtra("registerstate","bufferedReader.readLine()失败");
}
Log.i("mss",re);
如果在声明re时使用re =null;Log.i(“mss”,re);输出的是null{“status”:1},如果换成re=”“,就不会在解析的字符串中出现null
本文介绍在Android IntentService中解析从SSM接收到的JSON字符串的方法。通过HttpURLConnection获取响应消息并读取输入流,将读取到的数据拼接成完整的JSON字符串。针对不同异常情况,如读取失败等,向Intent中添加了错误信息。
693

被折叠的 条评论
为什么被折叠?



