我将 json 数组作为参数传递给其他活动,但是当我单击时会在文本中显示所有值,请在星期一查看此图像
http://postimg.org/image/fbjlm8y97/91beaa03/
显示在其他活动上,例如http:// postimg.org/image/8m0f1bjaf/987e8eb4/
字符串中的所有内容如何在 TextView 中仅显示名称?现在每件事我如何解析 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");