【问题标题】:How to show json response in other activity?如何在其他活动中显示 json 响应?
【发布时间】:2014-12-09 06:24:55
【问题描述】:

我正在创建一个应用程序,在我的应用程序中我正在使用 json 解析,我正在向服务器发送请求

点击按钮后会发送请求,我会得到响应

{"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"}
  ]
}

我想在另一个活动中显示此响应

【问题讨论】:

  • 在您的此活动中解析此响应并使用捆绑或意图传递其他活动中的值并在那里使用它,或者您可以传递整个 json 然后解析其他活动中的值并使用它
  • 我已经通过了整个 json,但是我如何在那里打印响应?
  • 你必须解析json中的值才能显示值
  • 是的,但我该怎么做呢?
  • google 一些教程以及如何在 android 上解析 json 这将是一个很好的起点androidhive.info/2014/09/android-json-parsing-using-volley

标签: android json android-activity android-listview


【解决方案1】:

解析您收到的响应,并将其与您创建的自定义对象一起存储在 arrayList 中,以存储您的每个响应行。

{"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"}

这是你的一行,所以对象类是这样的 -

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;
...
...
...

}

还有Like this link,把你的数据放在意图中,

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

并在下一个活动中检索:

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

【讨论】:

【解决方案2】:

将响应数据存储在地图中并将其传递给下一个活动。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-06-12
    • 1970-01-01
    • 2016-10-31
    • 1970-01-01
    相关资源
    最近更新 更多