How can i pass whole JSON array from main activity to other activity?

46 views Asked by At

I want full JSON data from an API to show in other activity. Tell me how I can do that.

2

There are 2 answers

0
Asif A. Sohan On

You can not directly pass JSON data to another activity. You can convert the JSON data to String and pass as extra with the inetent to another activity and retrieve the data.

intent.putExtra("JSON_DATA", json_object.toString());
startActivity(intent);

Retrieve data:

try {
   json_object = new JSONObject(getIntent().getStringExtra("JSON_DATA"));
} catch (JSONException e) {
   e.printStackTrace();
}
0
axar On

using gson you can pass JSON Array data from one activity to another

Reference Url - https://gist.github.com/WrathChaos/5f39e3ce3874a049d25e2ca8958d18b6