android studio jason文件解析基础
2016-07-23 11:21
483 查看
解析jason中非数组元素:
tv=(TextView)findViewById(R.id.text); String jsonstr="{\"name\":\"ailsa\",\"age\":22,\"arr\":[1,2,\"hello\"]}"; try { JSONObject jsonObject=new JSONObject(jsonstr); String name=jsonObject.getString("name"); tv.setText(name); } catch (JSONException e) { e.printStackTrace(); }
解析jason中数组元素:(如何这里不能正常输出,可以尝试重启studio)
tv=(TextView)findViewById(R.id.text); String jsonstr="{\"name\":\"ailsa\",\"age\":22,\"arr\":[1,2,\"hello\"]}"; try { JSONObject jsonObject=new JSONObject(jsonstr); JSONArray arr=jsonObject.getJSONArray("arr"); int value=arr.getInt(0); System.out.println(value); } catch (JSONException e) { e.printStackTrace(); }
相关文章推荐
- 安卓Android studio导入Github中的项目
- Gradle依赖的统一管理
- Android 解决使用SearchView时软键盘不支持actionSearch的问题
- Android的进程与线程
- Android报错:Out of memory on a 14745612-byte allocation.解决办法
- android studio 显示网页源码 inputstream bufferedreader stringbuffer
- Android Studio如何快速生成get,set,tostring,构造函数
- Android Context 上下文 你必须知道的一切
- 资源导致部分机型的兼容问题--安卓
- EventBus 3.0 事件总线
- Android 通过JNI实现守护进程,使得Service服务不被杀死
- Android简易实战教程--第八话《短信备份~一》
- Android简易实战教程--第八话《短信备份~一》
- Android 实现不依赖焦点和选中的TextView跑马灯
- layout的均分设置
- 【Android】友盟社会化分享
- Android studio 多环境打包和多渠道打包
- Android Studio插件ADB WIFI(让调试飞起)
- android学习之ListView如何使用
- Android教育项目Bug总结