Android JSON解析
2016-02-14 16:02
260 查看
String json = "{" + "\"languages\" : [" + "{\"id\":1,\"ide\":\"Eclipse\",\"name\":\"Java\"}," + "{\"id\":2,\"ide\":\"XCode\",\"name\":\"Swift\"}," + "{\"id\":3,\"ide\":\"Visual Studio\",\"name\":\"C#\"}" + "]," + "\"cat\" : \"it\"" + "}"; try { JSONObject root = new JSONObject(json); String all = ""; String cat = "cat = " + root.getString("cat") + "\n"; all = all + cat; JSONArray array = root.getJSONArray("languages"); for (int i = 0;i < array.length();i++) { JSONObject lan = array.getJSONObject(i); String sep = "-------------------------" + "\n"; String id = "id = " + lan.getInt("id") + "\n"; String name = "name = " + lan.getString("name") + "\n"; String ide = "ide=" + lan.getString("ide") + "\n"; all = all + sep + id + name + ide; } tv = (TextView)findViewById(R.id.all); tv.setText(all); } catch(JSONException e) { Toast.makeText(MainActivity.this,"error",Toast.LENGTH_LONG).show(); }
相关文章推荐
- Android消息处理系统原理简要概述
- ANDROID_MARS学习笔记_S01原始版_009_下载文件
- Android电话事件案例
- android开发中英文切换
- android:giavity和layout_gravity的区别
- Android类参考---Fragment
- 让动画不再僵硬:Facebook Rebound Android动画库介绍
- 看Android开发笔记之:消息循环与Looper的详解有感
- Android 接入支付宝支付只需十分钟
- Android Studio发布项目到jcenter升级版
- android的Unable to instantiate activity ComponentInfo异常
- android SharedPreferences详解
- android.intent.category.LAUNCHER的作用
- Android 仿知乎日报在切换Fragment页面,按back返回时,同步修改Toolbar的title。
- 【读书笔记】【Android 开发艺术探索】第11章Android 的线程和线程池
- [读书笔记]《Android开发艺术探索》第四章笔记
- “Genymotion运行Android模拟器一直卡在开机界面”的解决办法
- Android Touch事件传递机制
- Android屏幕适配
- Android本地数据存储