-
Android json解析问题30
这样的的格式的json数据怎么解析呢
[{"id":"24","bigtype":"生命","image":"1.jpg"},{"id":"23","bigtype":"生活","image":"2.png"},{"id":"22","bigtype":"河健康","image":"3.png"},{"id":"21","bigtype":"财运","image":"4.png"},{"id":"20","bigtype":"girl","image":"5.png"},{"id":"19","bigtype":"好运","image":"6.png"}]
问题补充:liuqing_2010_07 写道这是一个list吧!、
就是一个从服务器上面读取的一个json格式的数据啊,不知道怎么去解析
问题补充:String str ="[{"id":"24","bigtype":"生命","image":"1.jpg"},{"id":"23","bigtype":"生活","image":"2.png"},{"id":"22","bigtype":"河健康","image":"3.png"},{"id":"21","bigtype":"财运","image":"4.png"},{"id":"20","bigtype":"girl","image":"5.png"},{"id":"19","bigtype":"好运","image":"6.png"}] " ;
JSONObject jsonObject = new JSONObject(str);
在执行时就报错01-08 13:18:41.183: E/AndroidRuntime(19253): Caused by: org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject 不嫩从String转换成jsonObject
到底怎么回事啊?
问题补充:还是不行啊,还是会在执行
JSONObject jsonObject = new JSONObject(str);
报类型转换的异常
问题补充:renpeng301 写道你返回的json字符串可能要转换下 String jsonstr="[color=red][b] {List: [/b][/color] \"[{\"id\":\"24\",\"bigtype\":\"生命\",\"image\":\"1.jpg\"},{\"id\":\"23\",\"bigtype\":\"生活\",\"image\":\"2.png\"},{\"id\":\"22\",\"bigtype\":\"河健康\",\"image\":\"3.png\"},{\"id\":\"21\",\"bigtype\":\"财运\",\"image\":\"4.png\"},{\"id\":\"20\",\"bigtype\":\"girl\",\"image\":\"5.png\"},{\"id\":\"19\",\"bigtype\":\"好运\",\"image\":\"6.png\"}] [color=red]}[/color] "; JSONObject jsonObject = new JSONObject(jsonstr.toString()); JSONArray arrayJson = jsonObject .getJSONArray("List"); for(int i=0;i<arrayJson.length();i++) { 71 72 JSONObject tempJson = arrayJson.optJSONObject(i); 73 74 Log.d(TAG, tempJson.getString("id")); 75 Log.d(TAG, tempJson.getString("bigtype")); 76 Log.d(TAG, tempJson.getString("image")); 77 }
是不是我从服务器上面读取的数据不符合格式啊2012年1月07日 20:47
16个答案 按时间排序 按投票排序
-
可以考虑使用传递xml文件格式的时候 为了提高传递效率 可以考虑使用gzip压缩 再使用android自动的pull进行解析 用着非常不错呀
2012年1月10日 13:05
-
import org.json.*;
String json = "[{\"id\":\"24\",\"bigtype\":\"生命\",\"image\":\"1.jpg\"},{\"id\":\"23\",\"bigtype\":\"生活\",\"image\":\"2.png\"},{\"id\":\"22\",\"bigtype\":\"河健康\",\"image\":\"3.png\"}, {\"id\":\"21\",\"bigtype\":\"财运\",\"image\":\"4.png\"}, {\"id\":\"20\",\"bigtype\":\"girl\",\"image\":\"5.png\"},{\"id\":\"19\",\"bigtype\":\"好运\",\"image\":\"6.png\"}] ";
try {
JSONArray jsonArray = new JSONArray(json);
int arrayLength = jsonArray.length();
final String[] keys = { "id", "bigtype", "image"};
for(int index = 0; index < arrayLength; index++) {
JSONObject jsonObject = (JSONObject) jsonArray.get(index);
for(String key: keys) {
Log.d(key, jsonObject.getString(key));
}
}
} catch (JSONException e) {
e.printStackTrace();
}2012年1月09日 12:28
-
不是 你这个是 list to json 生成的数据吧· 那你这样吧 JSONObject jsonObject = JSONObject.fromObject(jsonstr); List<TestBean> list = new ArrayList<TestBean>(); for (Iterator iterator = jsonObject.keySet().iterator(); iterator.hasNext();) { list.add((TestBean)JSONObject.toBean(jsonObject.getJSONObject(iterator.next().toString()), TestBean.class)); } public class TestBean{ String id; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getBigtype() { return bigtype; } public void setBigtype(String bigtype) { this.bigtype = bigtype; } public String getImage() { return image; } public void setImage(String image) { this.image = image; } String bigtype; String image; }
2012年1月08日 18:10
-
你返回的json字符串可能要转换下 String jsonstr="[color=red][b] {List: [/b][/color] \"[{\"id\":\"24\",\"bigtype\":\"生命\",\"image\":\"1.jpg\"},{\"id\":\"23\",\"bigtype\":\"生活\",\"image\":\"2.png\"},{\"id\":\"22\",\"bigtype\":\"河健康\",\"image\":\"3.png\"},{\"id\":\"21\",\"bigtype\":\"财运\",\"image\":\"4.png\"},{\"id\":\"20\",\"bigtype\":\"girl\",\"image\":\"5.png\"},{\"id\":\"19\",\"bigtype\":\"好运\",\"image\":\"6.png\"}] [color=red]}[/color] "; JSONObject jsonObject = new JSONObject(jsonstr.toString()); JSONArray arrayJson = jsonObject .getJSONArray("List"); for(int i=0;i<arrayJson.length();i++) { 71 72 JSONObject tempJson = arrayJson.optJSONObject(i); 73 74 Log.d(TAG, tempJson.getString("id")); 75 Log.d(TAG, tempJson.getString("bigtype")); 76 Log.d(TAG, tempJson.getString("image")); 77 }
2012年1月08日 15:00
-
" \"[{\"id\":\"24\",\"bigtype\":\"生命\",\"image\":\"1.jpg\"},{\"id\":\"23\",\"bigtype\":\"生活\",\"image\":\"2.png\"},{\"id\":\"22\",\"bigtype\":\"河健康\",\"image\":\"3.png\"},{\"id\":\"21\",\"bigtype\":\"财运\",\"image\":\"4.png\"},{\"id\":\"20\",\"bigtype\":\"girl\",\"image\":\"5.png\"},{\"id\":\"19\",\"bigtype\":\"好运\",\"image\":\"6.png\"}] ";
你双引号 没有转义 你看看我给你发的字符串 。2012年1月08日 13:31
-
上面的Gson下载地址 时而不好使 ,但是能够下载。多试几次。
现在给你几个例子:
http://www.cnblogs.com/lupeng0527/archive/2011/08/06/2129547.html2012年1月08日 09:35
-
在adnroid上解析json 谷歌得 Google Gson(gson-xxx.jar)下载地址:http://code.google.com/p/google-gson/downloads/list 是很好得选择。。。
2012年1月08日 09:02
-
String jsonstr= " \"[{\"id\":\"24\",\"bigtype\":\"生命\",\"image\":\"1.jpg\"},{\"id\":\"23\",\"bigtype\":\"生活\",\"image\":\"2.png\"},{\"id\":\"22\",\"bigtype\":\"河健康\",\"image\":\"3.png\"},{\"id\":\"21\",\"bigtype\":\"财运\",\"image\":\"4.png\"},{\"id\":\"20\",\"bigtype\":\"girl\",\"image\":\"5.png\"},{\"id\":\"19\",\"bigtype\":\"好运\",\"image\":\"6.png\"}] "; JSONObject jsonObject = new JSONObject(jsonstr.toString()); String id = jsonObject .get("id").toString(); String bigtype= jsonObject .get("bigtype").toString(); String image= jsonObject .get("image").toString();
2012年1月08日 08:13
-
不写了 你直接 去看看 这个吧。
http://wenku.baidu.com/view/2b12c4a00029bd64783e2cc7.html
http://www.cnblogs.com/tt_mc/archive/2011/01/04/1925327.html
2012年1月07日 21:14
-
引用
就是一个从服务器上面读取的一个json格式的数据啊,不知道怎么去解析
我的天这个是在手机前台解释 我那白写了。。。。。呜呜。。。。。。。2012年1月07日 21:11
-
public class MyBean { String id; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getBigtype() { return bigtype; } public void setBigtype(String bigtype) { this.bigtype = bigtype; } public String getImage() { return image; } public void setImage(String image) { this.image = image; } String bigtype; String image; }
public Object getMyBean(Class pojoCalss) { String res = " \"[{\"id\":\"24\",\"bigtype\":\"生命\",\"image\":\"1.jpg\"},{\"id\":\"23\",\"bigtype\":\"生活\",\"image\":\"2.png\"},{\"id\":\"22\",\"bigtype\":\"河健康\",\"image\":\"3.png\"},{\"id\":\"21\",\"bigtype\":\"财运\",\"image\":\"4.png\"},{\"id\":\"20\",\"bigtype\":\"girl\",\"image\":\"5.png\"},{\"id\":\"19\",\"bigtype\":\"好运\",\"image\":\"6.png\"}] "; JSONArray jsonArray = JSONArray.fromObject(jsonString); JSONObject jsonObject; Object pojoValue; List list = new ArrayList(); for ( int i = 0 ; ijsonArray.size(); i++){ jsonObject = jsonArray.getJSONObject(i); pojoValue = JSONObject.toBean(jsonObject,pojoClass); list.add(pojoValue); } return list; }
你看看 这个行不行。
2012年1月07日 21:09
相关推荐
Android_JSON数据解析 博客里面的Demo
Android Json 解析demo 建立,基于Android stdio
android json 解析jar包。没有积分可以取GitHub上下载
android 项目开发实例,json 解析参考, 希望对你们有用
自己写的json解析,不使用第三方的jar包,简单易懂,分为本地json解析和online json解析,网上的只需要修改一下url地址即可
android json解析demo,简单粗暴
android框架解析JSON数据放入ListView的例子
Android JSON解析
Android json解析jar包,挺方便的解析jar包。
eclipse项目。获取raw文件下的json文件。无需编写json数据里面key值的实体类,动态获取里面的键值对的值。并在列表显示
AndroidJSON解析框架GSON,可以方便的解析JSON,提高效率,欢迎大家下载使用。
Android JSON解析示例代码.txt
android JSon解析例子,希望可以帮助大家。
android json数据下载与解析demo,实现了http下载json服务器数据,并通过JsonObject解析json数据
老罗android 解析json数据源码
本Demo验证了在安卓环境下使用Json的Key作为反序列化条件的解析速度。结论是解析速度最快的不是阿里的fastjson,也不是Google的Gson,而是...
Android 与后台交互,Json数据传输解析
Android 实用的数据json数据解析封装类,能快速解析任何形式json数据
android封装的json解析,可以直接解析对象或者list 如果有不明白的地方,可以联系我: QQ:840950105 Email:vipa1888@163.com Author:spring sky
android json 解析 json数据格式解析我自己分为两种; 一种是普通的,一种是带有数组形式的;