com.google.gson string to JsonObject
2016-09-27 14:33
375 查看
gson 中字符串转换为json数据:
String testString="'[b]bgColorPc ':'red'";[/b]
JsonObject jsondetail = new JsonParser().parse([b]testString).getAsJsonObject();[/b]
String bgColorPc = jsondetail.get("bgColorPc").getAsString();
这样就得到了jsonObject对象了,并且得到了jsonObject对象的值
方法二;
JsonElement jelem=gson.fromJson(json,JsonElement.class);
JsonObject jobj=jelem.getAsJsonObject();
gson 指南
https://sites.google.com/site/gson/gson-user-guide#TOC-Primitives-Examples
gson中字符串转化为固定对象
String colorTotal=“”;
JifenBgColorExtendDo bgColor=new Gson().fromJson(colorTotal, JifenBgColorExtendDo.class);
这样就可以将字符串转化为对象了
不过字符串中的key值要与对象的值一一对应
String testString="'[b]bgColorPc ':'red'";[/b]
JsonObject jsondetail = new JsonParser().parse([b]testString).getAsJsonObject();[/b]
String bgColorPc = jsondetail.get("bgColorPc").getAsString();
这样就得到了jsonObject对象了,并且得到了jsonObject对象的值
方法二;
JsonElement jelem=gson.fromJson(json,JsonElement.class);
JsonObject jobj=jelem.getAsJsonObject();
gson 指南
https://sites.google.com/site/gson/gson-user-guide#TOC-Primitives-Examples
gson中字符串转化为固定对象
String colorTotal=“”;
JifenBgColorExtendDo bgColor=new Gson().fromJson(colorTotal, JifenBgColorExtendDo.class);
这样就可以将字符串转化为对象了
不过字符串中的key值要与对象的值一一对应
相关文章推荐
- 06-I/O Stream: Object and Class
- iOS 开发-Objective-c基础:协议和代理delegate&protocol)
- ffmpeg: error while loading shared libraries: libavdevice.so.57: cannot open shared object file: No
- 微信小程序把玩(三十)wx.request(object) API
- 项目启动报错.NoClassDefFoundError: org/codehaus/jackson/map/ObjectMapper
- 使用fastjson的parseObject方法将json字符串转换成Map
- error LNK1104: 无法打开文件“acedapi.lib”
- Non Schema Object 的取得
- OHEM安装运行(Training Region-based Object Detectors with Online Hard Example Mining)
- java.lang.NoClassDefFoundError: org/objectweb/asm/Type
- GV$LOCKED_OBJECT
- jQuery find events handlers registered with an object
- OBJECT ARX 修改选中实体的颜色 选择集的使用
- iOS objective-c 判断field 是否带ASCII 码
- warning: could not load any Objective-C class information. This will significantly reduce the qualit
- 关于object类的clone方法浅克隆与深度克隆
- g++编译报错原因分析cannot allocate an object of abstract type“XXX ”
- java中的Object类
- 编译运行出现:__NSCFConstantString countByEate:objects:count: ?
- java.lang.Object源码浅析