Я создаю приложение, в котором я хочу o передать json-массив между двумя действиями. Как передать json arry из одной активности в другую с помощью намерений в android. может кто-нибудь мне помочь? спасибо
Передача jsonarray из одной активности в другую
Ответ 1
Преобразуйте JsonArray в String, затем присоедините его к Intent и отправьте его.
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);
Где jObject4 - объект JSON.
Получить следующую страницу:
Bundle b = getIntent().getExtras();
String Array=b.getString("Array");
Ответ 2
Intent intent = new Intent(your_activity.this, new_activity.class);
intent.putExtra("jsonArray", mJsonArray.toString());
startActivity(intent);
В следующем действии
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();
}