java对象转map json,转换JSON字符串到Java对象或HashMap的

I am writing an android app. I want to pass some data across the intents/activities and I feel that a conversion to and from JSON is probably a more optimal way at this point. I am able to convert a java hashmap to a json string successfully using JSONObject support.

However i need to convert back this JSON string to a java object or a hashmap. What is the best way to go about it.

Is parcelable really a change worth doing; if I have simple 5 field object? What are the other ways to transfer data between intents.

Cheers

解决方案

I recommend to pick Gson for that. It has excellent support for generics and fullworthy Javabeans and really eases the conversion task. In this answer you can find an example to convert a Map to JSON and vice versa and in this answer another example to convert a JSON string to a fullworthy Javabean (from Javabean to JSON is pretty simple with gson.toJson(bean).

Other ways to transfer data are XML and serialization, both which have much more overhead than JSON.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值