json字符串解析

来源:互联网 发布:c语言入门pdf下载 编辑:程序博客网 时间:2024/06/10 15:32
.

1.Gson解析 Gson gson =new Gson(); Type type = new TypeToken<List<String>>(){}.getType();
 List<String> o = gson.fromJson(string,type);
 content.setText(o.get(index));
2.json解析
   List<String> list=new ArrayList<String>();
   JSONArray jsonArray = new JSONArray(string);   for (int i=0;i<jsonArray.length();i++){    list.add(jsonArray.getString(i));   }  content.setText(list.get(index));
3.
JSONObject解析
JSONObject jsonObj = null;try {    jsonObj = new JSONObject(s);    String msg = jsonObj.getString("msg");    Toast.makeText(Deng.this,"---"+s,Toast.LENGTH_LONG).show();   if(msg.equals("登陆成功")){        Toast.makeText(Deng.this,"---登陆成功",Toast.LENGTH_LONG).show();    }} catch (JSONException e) {    e.printStackTrace();}

原创粉丝点击