[英]How to get array of object of object and their response using setter and getter method
"Status": "success",
"data": [
{
"lead_id": "13653",
"bp_id": "5d832cbeb4a36302da065233",
"BP_consumer_id": 32,
"agent_id": "56",
"vertical_stage": "Meeting",
"bp_vertical": {
"vertical_name": "Mahesh Tutorials",
"vertical_url": "http://mteducare.com",
"category": "Agriculture/Food Processing",
"sub_category": "Food",
"isActive": "yes",
"NPS_rating": [
{
"promoter": {
"1": {
"relates_to": "5b2b2a28613b6ad01c014a29",
"reasons": "Great product looks,Good product features,Product fits my need"
},
"2": {
"relates_to": "5b2b2a9a613b6ad01c014a60",
"reasons": "Value for Money"
},
"3": {
"relates_to": "5b2b2a9a613b6ad01c014a62",
"reasons": "Informative Advertisement,Informative Web-site,Informative Brochure"
},
"4": {
"relates_to": "5b754201b9bdada1ab2bc940",
"reasons": "Informative Sales person,Delivery / Installation"
},
"5": {
"relates_to": "5b754201b9bdada1ab2bc942",
"reasons": "I Love Godrej products,Positive Social Media reviews"
},
"6": {
"relates_to": "5b754201b9bdada1ab2bc944",
"reasons": "Other Issue"
},
"promoter_title": "Thank-you for High Ratings, give us your compliments"
},
"passive": {
"1": {
"relates_to": "5b2b2a28613b6ad01c014a29",
"reasons": "Great product looks,Good product features,Product fits my need"
},
"2": {
"relates_to": "5b2b2a9a613b6ad01c014a60",
"reasons": "Value for Money"
},
"3": {
"relates_to": "5b2b2a9a613b6ad01c014a62",
"reasons": "Informative Advertisement,Informative Web-site,Informative Brochure"
},
"4": {
"relates_to": "5b754201b9bdada1ab2bc940",
"reasons": "Informative Sales person,Delivery / Installation"
},
"5": {
"relates_to": "5b754201b9bdada1ab2bc942",
"reasons": "I Love Godrej products,Positive Social Media reviews"
},
"6": {
"relates_to": "5b754201b9bdada1ab2bc944",
"reasons": "Other Issue"
},
"passive_title": "Thank you for your Ratings, what went well ?"
},
}
],
"short_url": "b6zdm32",
"shared_url": "http://mteducare.com?32"
},
"pledge_id": "5d8c9005b4a363703c0d0234",
"noOfOffersToBeSelected": "3"
}
],
"code": 200
}
首先使用在线转换器http://www.jsonschema2pojo.org/将您的 json 转换为 POJO
然后在 Java 使用下面的代码更改 getString('yourkeyValue') 键按照 JSON pojo
public void onSuccess(Object result) {
try {
JSONObject jsonObject = new JSONObject(new JSONTokener(result.toString()).nextValue().toString());
if (jsonObject.getString("responseCode").equals("00")) {
JSONObject jresponseData = new JSONObject(jsonObject.getString("responseData"));
if (jresponseData.has("Table1")) {
JSONArray jsonArray = new JSONArray(jresponseData.getString("Table1"));
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jsonObject1 = jsonArray.getJSONObject(i);
MyPojo listObj = new MyPojo();
String sName = StringUtils.defaultIfEmpty(jsonObject1.getString("s_Name"), "").replace("null", "");
String s_desc = StringUtils.defaultIfEmpty(jsonObject1.getString("s_About"), "").replace("null", "");
String simgUrl = StringUtils.defaultIfEmpty(jsonObject1.getString("Image").replace("@", ""), "");
String pk_id = StringUtils.defaultIfEmpty(jsonObject1.getString("PK_ID"), "0");
listObj.setChannelName(sName);
listObj.setS_shortDes(s_desc);
}
}
}
}
}
There are multiple ways you can get it from the server using Rxjava and retrofit and volly, - Refer this link to how to use retrofit https://www.androidhive.info/2016/05/android-working-with-retrofit-http -图书馆/
您可以使用 android 工作室中的 DTO 生成器插件从 JSON 生成 getter 和 setter。
否则您可以使用http://pojo.sodhanalibrary.com/链接生成 getter 和 setter
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.