开发者

passing jsonarray from 1 activity to another

开发者 https://www.devze.com 2023-04-11 04:53 出处:网络
I am m开发者_C百科aking an app in which I want o pass a json array between 2 activities .how to pass json arry from one activity to another through intents in android. can anybody help me over this??

I am m开发者_C百科aking an app in which I want o pass a json array between 2 activities .how to pass json arry from one activity to another through intents in android. can anybody help me over this?? thanks


Intent intent = new Intent(your_activity.this, new_activity.class);
intent.putExtra("jsonArray", mJsonArray.toString());
startActivity(intent);

In the next Activity

        Intent intent = getIntent();
        String jsonArray = intent.getStringExtra("jsonArray");

        try {
            JSONArray array = new JSONArray(jsonArray);
            System.out.println(array.toString(2));
        } catch (JSONException e) {
            e.printStackTrace();
        }


You should convert JsonArray to String then attach it to Intent and send it.

JSONObject jObject = new JSONObject("Your Json Response");
Intent obj_intent = new Intent(Main.this, Main1.class);
Bundle b = new Bundle();                
b.putString("Array",jObject4.toString());
obj_intent.putExtras(b);

Where jObject4 is JSON Object.

Get in next Page :

Bundle b = getIntent().getExtras();
String Array=b.getString("Array");
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号