2

I am trying to map following data to POJOs but having no clue how to handle it, I have to map this data and finally show it in recycler view cards.
Till now I have create a ScoreCard class, and SingleInning Class.

Main problem I am facing is when looping through past_ings array, I have no idea how to store another array array or sub Object in it. Like how to store and how to get the value in onBinderViewHolder in my Adapter.

{
 "query": {
 "count": 1,
 "created": "2017-08-13T19:57:10Z",
 "lang": "en-US",
 "results": {
 "Scorecard": {
 "v": "0",
 "mid": "196674",
 "m": "1",
 "ecf": "0",
 "mn": "3rd Test",
 "ps": "0",
 "past_ings": [
     {
      "s": {
        "m": "1",
        "t": "1",
        "i": "3",
        "ps": "0",
        "stay_live": "Yes",
        "ld": "No",
        "ldmsg": null,
        "pms": "live",
        "dm": "Day 2",
        "sn": "3",
        "d": "Stumps",
        "a": {
           "fo": "1",
           "pp": null,
           "i": "8",
           "cr": "1.46",
           "r": "19",
           "o": "13",
           "w": "1",
           "b": "0",
           "lb": "0",
           "wd": "0",
           "nb": "0",
           "pt": "0",
           "l": "0",
           "tl": "trails by 333"
       }
    }
   },
    {
      "s": {
        "m": "1",
        "t": "1",
        "i": "3",
        "ps": "0",
        "stay_live": "Yes",
        "ld": "No",
        "ldmsg": null,
        "pms": "live",
        "dm": "Day 2",
        "sn": "3",
        "d": "Stumps",
        "a": {
        "fo": "1",
        "pp": null,
        "i": "8",
        "cr": "1.46",
        "r": "19",
        "o": "13",
        "w": "1",
        "b": "0",
        "lb": "0",
        "wd": "0",
        "nb": "0",
        "pt": "0",
        "l": "0",
        "tl": "trails by 333"
       }
      }
     }
    ]
   }
  }
 }
}
Code_Lover
  • 134
  • 2
  • 11
  • You can use jackson to map this to pojo – Johny Aug 15 '17 at 18:16
  • Possible duplicate of [How to convert POJO to JSON and vice versa?](https://stackoverflow.com/questions/9593409/how-to-convert-pojo-to-json-and-vice-versa) – Johny Aug 15 '17 at 18:23

1 Answers1

3

Ok you can use this web site for this

http://www.jsonschema2pojo.org/

You put your copy your json and Source type: Json and Annotation style:Gson and click preveiew and that's it will generta the class you need to get the data

enter image description here

Let say you want the stay a life value of the first S object will be like this

    String stay_live= 
respnse.getQuery().getResults().getScorecard().getPastIngs().get(0).getS().getStayLive()
Ahmed Abd-Elmeged
  • 1,654
  • 2
  • 13
  • 28