[英]How to parse this nested complex JSON into POJO
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. 我正在尝试将以下数据映射到POJO,但不知道如何处理它,我必须映射此数据并最终在回收者视图卡中显示它。
Till now I have create a ScoreCard class, and SingleInning Class. 到目前为止,我已经创建了一个ScoreCard类和SingleInning类。
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. 我面临的主要问题是遍历past_ings数组时,我不知道如何在其中存储另一个数组或子对象。 Like how to store and how to get the value in onBinderViewHolder in my Adapter.
就像如何在我的适配器中的onBinderViewHolder中存储和获取值。
{
"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"
}
}
}
]
}
}
}
}
Ok you can use this web site for this 好的,您可以使用此网站
http://www.jsonschema2pojo.org/ 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 您将自己的json和Source类型放入副本:Json和Annotation style:Gson并单击preveiew,这将生成您需要获取数据的类
Let say you want the stay a life value of the first S object will be like this 假设您希望第一个S对象的生命值保持不变
String stay_live=
respnse.getQuery().getResults().getScorecard().getPastIngs().get(0).getS().getStayLive()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.