0

Recently, in my web server, to get JSON text, I'm using AsyncTask

    String strData = "";

@Override
protected void onPostExecute(String result) {
   super.onPostExecute(result);

final ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1);
try {
    JSONArray arr =new JSONArray(result);
       JSONObject ob = arr.getJSONObject(0);       
       strData += ob.getString("name") + "\n"
               + " - " + ob.getString("school") + "\n"
               + " - " + ob.getString("job") + "\n\n";
       adapter.add(strData);
} catch (JSONException e) {
   Log.d(TAG,"DD");
} 
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(adapter);
}

result

aaa
- seoul university
- teacher

and I want JSON parser value use intent.putExtra another activity.

I don't know

Intent intent = new Intent(this, anotheractivity.class);
 intent.putExtra("information","I don't know here");
 startActivity(intent);

I want school.job data another activity transport.

how to use data transport JSON parser data?

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
chohyunwook
  • 411
  • 1
  • 5
  • 18
  • please try to explain your problem more clearly, it is hard to understand right now – Vivek Mishra Aug 29 '16 at 09:26
  • if you want to send data from json via intent extra try like this `intent.putExtra("information","ob.getString("job")");` – Logic Aug 29 '16 at 09:29
  • This will solve your purpose. http://stackoverflow.com/questions/37208243/how-to-pass-list-object-between-fragment/37208349#37208349 – Sreehari Aug 29 '16 at 09:46

3 Answers3

0

Parse your Json inside an object of the same structure, then pass that object with the intent

University uni = new University();
uni.setTitle(jsonObj.getJSONObject("Title").opt("val").toString());
Intent i = new Intent(this, anotheractivity.class);
i.putExtra("information", uni);

then you can get your object from the Intent in your other activity

Nadir Belhaj
  • 11,953
  • 2
  • 22
  • 21
0

A simple way to get the data in another activity is

To put JSon string in putExtra() and then get the string, parsing it into JSON objects in another activity.

Snow.T
  • 23
  • 6
0
As per your code:

    @Override 
    protected void onPostExecute(String result) {
       super.onPostExecute(result);

    final ArrayAdapter<String> adapter = new ArrayAdapter<String>(MainActivity.this, android.R.layout.simple_list_item_1);
    try { 
        JSONArray arr =new JSONArray(result);
           JSONObject ob = arr.getJSONObject(0);       
           strData += ob.getString("name") + "\n"
                   + " - " + ob.getString("school") + "\n"
                   + " - " + ob.getString("job") + "\n\n";
           adapter.add(strData);
    } catch (JSONException e) {
       Log.d(TAG,"DD");
    }  
    ListView listView = (ListView) findViewById(R.id.listView);
    listView.setAdapter(adapter);
    } 

    you are getting server response in result String, so just put the "result" in Intent as follows:

    Intent intent = new Intent(this, anotheractivity.class);
     intent.putExtra("result","result");
     startActivity(intent);

    In anotheractivity.class onCreate method:
    String result=getIntent().getStringExtra("result");
    Where result contain your JSON data.
Rajendra
  • 484
  • 4
  • 19