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.