2 wangruishilongfei wangruishilongfei 于 2014.08.25 21:42 提问

json中如果有数字作为key,使用Gson如何解析

json中如果有数字作为key,使用Gson如何解析
{"attImageMap":
{"22520696":{"OBJID":17436886,"DOCID":22520696,"TYPE":"jpg","LENGTH":378982,"CREATETIMESTAMP":"2014-08-19 18:40:59","UPDATETIMESTAMP":"2014-08-19 18:40:59","PAGE":1,"IMGCACHE":1,"PAGENUM":5},"22520229":{"OBJID":17436552,"DOCID":22520229,"TYPE":"jpg","LENGTH":104112,"CREATETIMESTAMP":"2014-08-19 17:58:23","UPDATETIMESTAMP":"2014-08-19 17:58:23","PAGE":1,"IMGCACHE":1,"PAGENUM":24},"22520650":{"OBJID":17436844,"DOCID":22520650,"TYPE":"jpg","LENGTH":433533,"CREATETIMESTAMP":"2014-08-19 18:37:20","UPDATETIMESTAMP":"2014-08-19 18:37:20","PAGE":1,"IMGCACHE":1,"PAGENUM":4},"22520208":{"OBJID":17436534,"DOCID":22520208,"TYPE":"jpg","LENGTH":461584,"CREATETIMESTAMP":"2014-08-19 17:55:47","UPDATETIMESTAMP":"2014-08-19 17:55:47","PAGE":1,"IMGCACHE":1,"PAGENUM":21},"22520649":{"OBJID":17436843,"DOCID":22520649,"TYPE":"jpg","LENGTH":415667,"CREATETIMESTAMP":"2014-08-19 18:37:21","UPDATETIMESTAMP":"2014-08-19 18:37:21","PAGE":1,"IMGCACHE":1,"PAGENUM":4},"22520493":{"OBJID":17436736,"DOCID":22520493,"TYPE":"jpg","LENGTH":642397,"CREATETIMESTAMP":"2014-08-19 18:36:18","UPDATETIMESTAMP":"2014-08-19 18:36:18","PAGE":1,"IMGCACHE":1,"PAGENUM":20},"22520239":{"OBJID":17436561,"DOCID":22520239,"TYPE":"jpg","LENGTH":631618,"CREATETIMESTAMP":"2014-08-19 17:59:28","UPDATETIMESTAMP":"2014-08-19 17:59:28","PAGE":1,"IMGCACHE":1,"PAGENUM":13},"22520746":{"OBJID":17436921,"DOCID":22520746,"TYPE":"jpg","LENGTH":599334,"CREATETIMESTAMP":"2014-08-19 18:49:09","UPDATETIMESTAMP":"2014-08-19 18:49:09","PAGE":1,"IMGCACHE":1,"PAGENUM":4},"22520481":{"OBJID":17436727,"DOCID":22520481,"TYPE":"jpg","LENGTH":512488,"CREATETIMESTAMP":"2014-08-19 18:22:58","UPDATETIMESTAMP":"2014-08-19 18:22:58","PAGE":1,"IMGCACHE":1,"PAGENUM":14},"22520471":{"OBJID":17436719,"DOCID":22520471,"TYPE":"jpg","LENGTH":465790,"CREATETIMESTAMP":"2014-08-19 18:20:25","UPDATETIMESTAMP":"2014-08-19 18:20:25","PAGE":1,"IMGCACHE":1,"PAGENUM":6},"22520584":{"OBJID":17436800,"DOCID":22520584,"TYPE":"jpg","LENGTH":307522,"CREATETIMESTAMP":"2014-08-19 18:20:23","UPDATETIMESTAMP":"2014-08-19 18:20:23","PAGE":1,"IMGCACHE":1,"PAGENUM":5},"22520426":{"OBJID":17436684,"DOCID":22520426,"TYPE":"jpg","LENGTH":412341,"CREATETIMESTAMP":"2014-08-19 18:15:46","UPDATETIMESTAMP":"2014-08-19 18:15:46","PAGE":1,"IMGCACHE":1,"PAGENUM":11},"22520405":{"OBJID":17436670,"DOCID":22520405,"TYPE":"jpg","LENGTH":509431,"CREATETIMESTAMP":"2014-08-19 18:16:48","UPDATETIMESTAMP":"2014-08-19 18:16:48","PAGE":1,"IMGCACHE":1,"PAGENUM":20},"22520231":{"OBJID":17436554,"DOCID":22520231,"TYPE":"jpg","LENGTH":371571,"CREATETIMESTAMP":"2014-08-19 18:00:30","UPDATETIMESTAMP":"2014-08-19 18:00:30","PAGE":1,"IMGCACHE":1,"PAGENUM":5}}}

1个回答

chquan88888
chquan88888   2015.09.23 15:20

使用@SerializedName("中国画")注解,给Key取别名。
http://www.cnblogs.com/bianmajiang/p/3998083.html

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!
其他相关推荐
当json中的key值为数字时,怎么用GSON解析?
一般json中的key值都是固定的,但如果key值为数字序列时应该怎么办呢?如下 { "0": { "count":"5"}, "1": { "title":"...", "desc":"" }, "2": { "title":"...", "desc":"" }, "3": { "title":"...", "desc":"" }, "4": { "title":"..."
解决Gson解析Json时,Json 中Key为Java关键字的问题
这里写链接内容
如何处理解析Json中的key为中文或数字等变态数据
这篇文章是介绍如何处理Json中一些key为中文或数字开头的奇葩数据,使用的工具是Google提供的Gson工具,采用的方法是编写Java bean类对应json数据中相应的对象及数组等。默认各位已掌握这些知识,关于gson的基本使用请自行百度。 Json变态数据案例{ "名称1": "这是个案例而已", "这是个demo": { "1e-3": 65.3,
解决fastjson、Jackson、Gson解析Json数据时,key为Java中关键字无法解析的问题
博文首次发布于个人博客:吾勇士的博客 无论我们在使用fastjson、Jackson还是Gson,我们在用json转换为实体类时,都是根据json数据建立对应实体类,但比较恶心的是,有时,有些服务商返回的json报文中,key值为java中的关键字,我们没法用关键字,当做一个类的成员变量,不过不代表我们就没有其他的办法解决了; 先给个测试实体类: ?
解析用Gson解析json遇到”一”:“二”类似字符串key,value,如何编写实体类
{"测A00007":["离线","离线"],"测A00006":["离线","离线"]}
Gson解析JSON中动态未知key的例程源码
我的博客中介绍的Gson解析JSON中动态未知key的例程源码,eclipse工程。
我的Android进阶之旅------>解决Jackson、Gson解析Json数据时,Json数据中的Key为Java关键字时解析为null的问题
1、问题描述首先,需要解析的Json数据类似于下面的格式,但是包含了Java关键字abstract: { ret: 0, msg: "normal return.", news: [ { id: "NEW2016062800875700", fro
JSON取值(key是中文或者数字)方式详解
先准备一个json对象用于演示var json = {'name':'zhangsan', '年龄':23, 404:'你可能迷路了'};使用JS中with关键字with(json) { console.log(name);//输出:zhangsan console.log(年龄);//输出:23 console.log(404);//输出:404,用这种方法读取key是数字
如何解析key为数字的string类型的Json数据
解析json
Gson解析JSON数据中动态未知字段key的方法
有时在解析json数据中的字段key是动态可变的时候,由于Gson是使用静态注解的方式来设置实体对象的,因此我们很难直接对返回的类型来判断。但Gson在解析过程中如果不知道解析的字段,就会将所有变量存储在一个Map中,我们只要实例化这个map就能动态地取出key和value了。先给出一段jsondata,这是天气预报的数据,其中day_20151002这种key是随日期而变化的,在实体类中就不能当做