A very handy built-in class to have is JSONTokener which I used for my Diablo II Runewords app.
public RunewordParser(String data) throws JSONException {
// Parse String "data"
JSONObject json = (JSONObject) new JSONTokener(data).nextValue();
// Some primitive data types
stones = json.getString("stones");
matched = json.getInt("matched");
onlyComplete = json.getBoolean("only_complete");
// Dealing with arrays
JSONArray runewords = json.getJSONArray("runewords");
for (int i = 0; i < runewords.length(); i++) {
Runeword runeword = new Runeword(runewords.getJSONObject(i));
this.runewords.add(runeword);
}
} That should be enough to get you started. If you've got any questions, leave a comment.

Amazing dude I was searching for something like that, but I'm troubles to fix this:
ReplyDeleteI have the following valid json response got from my java webservice:
************************************************
{
"auctions": [
{
"id": 13,
"name": "gadjet's auction",
"products": [
{
"description": "20639",
"id": 14,
"biggerBid": {
"value": 180
},
"name": "soapdish"
},
{
"description": "20640",
"id": 15,
"biggerBid": null,
"name": "Belt"
}
]
}
]
}
************************************************
I just want to get this json response through it's own regular url such as http://auction-server.herokuapp.com/auctions.json
and fill a listView with the incoming json's parsed Data.
If you could helpe me Too much appreciated, best regards!
Hi Marley,
ReplyDeleteI'm not sure where you're having issues, but this post may help you with the Listview stuff.
http://twigstechtips.blogspot.com/2012/01/android-displaying-items-in-listview.html