Stillie
Stillie

Reputation: 2676

Multiple JSON parsing

I need help with making a decision on parsing. I need to do JSON parsing. The way i was doing it was with one generic style network call using Volley and 1 massive switch case that would go to the relevant parse. I would add a String to the method called source so I knew what parsing needs to be done.

Initial call

private void getHomeScreen(){
   networkCall(
            url,         //Url used to make the call
            homeScreen);  //The source of the parsing
}

The response once the network call has completed sending it to the parser

onResponse{
   parser(
         jsonFile, //Response JSON file
         source);  //passing the String that had the source of the parser
}

The Parser method that sends the correct response to the correct parser

private void parser(JSONObject, String source){
 // the one massive switch case sending the HomeScreen to the relevant parser
}

Is there a better way to do this? there must be!

Thanks

Upvotes: 0

Views: 88

Answers (1)

Jelle van Es
Jelle van Es

Reputation: 673

If I were you I would look at Gson for android. Gson is a library that can easily parse JSON. So there is no need to make your own parsers. With Gson you can make model classes and all the parsing will be done for you.

Take a look at this tutorial:

http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html

Hope this helps.

Upvotes: 2

Related Questions