2016-08-29 6 views
0

にテントputExtra JSONデータを使用する方法、私はAsyncTaskJSONテキストを取得するには、自分のWebサーバーで、最近、アンドロイド

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); 
} 

結果

aaa 
- seoul university 
- teacher 

を使用していると私は、JSONパーサー値が欲しいですintent.putExtra別のアクティビティを使用してください。

私は、私は別のアクティビティ輸送school.jobデータが欲しい

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

を知りません。

データトランスポートJSONパーサーデータの使用方法は?

+0

より明確にあなたの問題を説明してみてください、あなたが余分な意図この 'intent.putExtra(「情報」、「ob.getStringのようにしてみてください経由でJSONのデータを送信したい場合は、今 –

+0

を理解することは困難です( "job") "); ' –

+0

これはあなたの目的を解決します。 http://stackoverflow.com/questions/37208243/how-to-pass-list-object-between-fragment/37208349#37208349 – Stallion

答えて

0

同じ構造のオブジェクト内のあなたのJSONを解析し、その後、あなたは他の活動

+0

大学とは何ですか?それは誤りです。:( – chohyunwook

+0

大学はあなたのクラスでそれを変更することができるクラスの例です –

0

簡単な方法にして意図から、あなたのオブジェクトを取得することができます意図

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

と、そのオブジェクトを渡します

putExtra() にJSon文字列を入れ、それを別のアクティビティのJSONオブジェクトに解析するには、次のようにします。

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. 
関連する問題