json配列をパラメーターとして他のアクティビティに渡しますが、クリックするとすべての値がテキストで表示されます。月曜日にこの画像を参照し
て
くださいpostimg.org/image/8m0f1bjaf/987e8eb4/
文字列内のすべてのものをTextViewで名前だけを表示するにはどうすればよいですか? 今、json配列を解析するにはどうすればよいですか???
Json :
{
"student": [
{
"id": 1,
"name": "Monday",
"dish": "Biryani",
"Gender": "M",
"age": 10,
"birthdate": "23/05/2002"
},
{
"id": 2,
"name": "Tuesday",
"dish": "Sandwish",
"Gender": "M",
"age": 12,
"birthdate": "08/01/2000"
},
{
"id": 3,
"name": "Wednesday",
"dish": "Chicken Tikka",
"Gender": "F",
"age": 14,
"birthdate": "01/03/1998"
},
コード:
try {
JSONObject mainJson = new JSONObject(result);
jsonArray = mainJson.getJSONArray(ARRAY_NAME);
for (int i = 0; i < jsonArray.length(); i++) {
objJson = jsonArray.getJSONObject(i);
Item objItem = new Item();
objItem.setId(objJson.getInt(ID));
objItem.setName(objJson.getString(NAME));
myname= objJson.getString(NAME);
objItem.setCity(objJson.getString(CITY));
objItem.setGender(objJson.getString(GENDER));
objItem.setAge(objJson.getInt(AGE));
objItem.setBirthdate(objJson.getString(BIRTH_DATE));
arrayOfList.add(objItem);
}
} catch (JSONException e) {
e.printStackTrace();
}
setAdapterToListview();
}
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if(!jsonArray.isNull(position)){
Intent intent = new Intent(SeletecDayofweek.this,TodayLunch.class);
intent.putExtra("name", jsonArray.optJSONObject(position).toString());
startActivity(intent);
}
}
and get like this
Intent intent = getIntent();
String stringRecd = intent.getStringExtra("name");