如何从 json 数组中过滤值我想过滤如果 string zero1check =0 在 Category_name.add(object.getString("dish_name")) 中仅添加该 json 数组;其中“天”:“m1”
如果 zero1check =0 添加 Category_name.add(object.getString("dish_name")); 只有包含 "day":"m2" 的 json 数组
{
"status":1,
"data":
[
{
"school_name":"testing12",
"menu_title":"Menu1",
"dish_name":null,
"day":"m1"
}
,
{
"school_name":"testing12"
,"menu_title":"Menu1",
"dish_name":null,
"day":"m1"
}
,
{
"school_name":"testing12"
,"menu_title":"Menu1",
"dish_name":null,
"day":"m2"
}
,
{
"school_name":"testing12"
,"menu_title":"Menu1",
"dish_name":null,
"day":"m2"
}
]
}
static ArrayList<Long> Category_ID = new ArrayList<Long>();
static ArrayList<String> Category_name = new ArrayList<String>();
static ArrayList<String> menu_name = new ArrayList<String>();
String zero1check;
JSONObject json2 = new JSONObject(str);
status = json2.getString("status");
if (status.equals("1")) {
JSONArray school = json2.getJSONArray("data");
for (int i = 0; i < school.length(); i++) {
JSONObject object = school.getJSONObject(i);
Category_ID.add((long) i);
Category_name.add(object.getString("dish_name"));
menu_name.add(object.getString("menu_title"));
String[] mVal = new String[school.length()];
for (int k = 0; k < school.length(); k++) {
mVal[k] =
school.getJSONObject(k).getString("menu_title");
menu_nametxt.setText(mVal[0]);
}