Android如何解析json数组对象
来源:互联网 发布:网络销售模式有哪些 编辑:程序博客网 时间:2024/06/05 11:43
json是种常用的数据传输格式,在android开发中,如何借助java语言实现对json数组对象的解析呢,请参阅下面的关键代码:
主要用到的类:JSONArray和JSONObject
android 读取json数据(遍历JSONObject和JSONArray)(转)
- public String getJson(){
- String jsonString = "{\"FLAG\":\"flag\",\"MESSAGE\":\"SUCCESS\",\"name\":[{\"name\":\"jack\"},{\"name\":\"lucy\"}]}";//json字符串
- try {
- JSONObject result = new JSONObject(jsonstring);//转换为JSONObject
- int num = result.length();
- JSONArray nameList = result.getJSONArray("name");//获取JSONArray
- int length = nameList.length();
- String aa = "";
- for(int i = 0; i < length; i++){//遍历JSONArray
- Log.d("debugTest",Integer.toString(i));
- JSONObject oj = nameList.getJSONObject(i);
- aa = aa + oj.getString("name")+"|";
- }
- Iterator<?> it = result.keys();
- String aa2 = "";
- String bb2 = null;
- while(it.hasNext()){//遍历JSONObject
- bb2 = (String) it.next().toString();
- aa2 = aa2 + result.getString(bb2);
- }
- return aa;
- } catch (JSONException e) {
- throw new RuntimeException(e);
- }
- }
原文: http://zhaojianping.blog.51cto.com/725123/629526
阅读全文
0 0
- Android如何解析json数组对象
- Android如何解析json数组对象
- Android如何解析json数组对象
- Android如何解析json数组对象
- Android如何解析json数组对象
- Android如何解析json数组对象
- Android解析json数组对象
- Json解析数组对象
- 解析json数组对象
- 解析Json对象数组
- android解析json数组
- android解析JSON数组
- Android 解析JSON 数组
- android解析json数组
- android json解析对象
- json 解析 数组中的对象
- java解析json对象,数组
- json解析数组和对象
- 你应该会的一道多线程笔试题
- C和指针之字符串简单实现 strcpy、strcat、strstr函数
- 织梦更新栏目出现500错误的解决办法
- VMware虚拟机三种联网方法及原理
- 人工智能神经网络算法零基础小白入门到高级实战必修之路精品教程
- Android如何解析json数组对象
- 148. Sort List
- 第七章 数据库设计 E-R模型
- JNI
- 理解字符串拼接
- 两个int(32位)整数m和n的二进制表达中,有多少个位(bit)不同?
- spring-data-redis模块详解
- cut操作详解
- 利用AJAX后台查询数据库返回json,前台生成表格