I'm trying to get the values out of this JSON string but I'm having a hard time achieving this.
{"DebugLogId":"1750550","RequestId":"17505503","Result":
{"Code":"","DebugLogId":"1750550","Message":""},
"Suggestions":[
{"Ranking":"1","Score":"60","Title":"This is a test message 1"},
{"Ranking":"2","Score":"60","Title":"This is a test message 2"}
]}
What way would be easiest to access the data in 'Suggestions'? I'm using the GSON module. Ideally I would like to put it all in a HashMap.
Thanks for any help and/or suggestions!
Thanks for any help!
I'm recommend you to use flexjson library http://flexjson.sourceforge.net/ IMHO, it more simple and usable library. I has used GSON first time, but then switched all my projects to flexjson instead of GSON.
Hope this helps:
App.java:
Debug.java:
Result.java:
Suggestion.java:
Using the standard json classes in android:
If you can switch libraries, Jackson can achieve that with just one line of code.
This would deserialize any JSON object into a
HashMap
, composed of just Java SE components. I haven't yet seen another Java-to/from-JSON library that can do that.The same can be accomplished with Gson, but it requires a few more lines of code. Here's one such solution.
(I copied this code from my blog post at http://programmerbruce.blogspot.com/2011/06/gson-v-jackson.html.)