How to show json response in other activity?

◇◆丶佛笑我妖孽 提交于 2019-12-22 01:31:15

问题


I am creating one application,in my application I am using json parsing,I am sending request to server for

after click on button request will be send,and i will get response

{"searchresult":
  [ {"match_detail_id":369,"profile_id":"GM686317","name":"Sonal Patel","image":"","location":"Rajkot ,Gujarat ,India","mothertongue":"Gujarati","religion":"Hindu","occupation":"Professor \/ Lecturer","education":"Masters - Arts\/ Science\/ Commerce\/ Others"}
  , {"match_detail_id":396,"profile_id":"GM780609","name":"Hetal Trivedi","image":"","location":"Rajkot ,Gujarat ,India","mothertongue":"Gujarati","religion":"Hindu","occupation":"Administrative Professional","education":"Bachelors - Arts\/ Science\/ Commerce\/ Others"}
  , {"match_detail_id":1078,"profile_id":"GM540027","name":"Shruti  Dave","image":"","location":"Rajkot ,Gujarat ,India","mothertongue":"Gujarati","religion":"Hindu","occupation":"Education Professional","education":"Masters - Arts\/ Science\/ Commerce\/ Others"}
  ]
}

I want to show this response in another activity


回答1:


Parse the response you have received, and store it in a arrayList with the custom object you create to store your each response line.

{"match_detail_id":369,"profile_id":"GM686317","name":"Sonal Patel","image":"","location":"Rajkot ,Gujarat ,India","mothertongue":"Gujarati","religion":"Hindu","occupation":"Professor \/ Lecturer","education":"Masters - Arts\/ Science\/ Commerce\/ Others"}

this is your one line, so object class would be like this -

public class ResultObejct implements parcelable {

    String match_detail_id;
    String profile_id;
    String name;
    String image;

    public String getName(){ //set getter and setters
    return this.name;
...
...
...

}

And Like this link, put your data in intent,

Intent i = new Intent(...);
i.putExtra("data", new DataWrapper(yourArrayList));

and retrieving in next activity:

DataWrapper dw = (DataWrapper) getIntent().getSerializableExtra("data");
ArrayList<Parliament> list = dw.getParliaments();



回答2:


Store the response data in a map and pass it to next activity.



来源:https://stackoverflow.com/questions/27372673/how-to-show-json-response-in-other-activity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!