我解析json數據成功,我可以在我的recyclerView上顯示它。json解析數據集搜索條件不起作用
這是我的數據源: (已經解決了這個問題) 我想設置搜索條件約month > 5
我已成立前的String.equal("compareString");
,它的工作。
但是,當我在這種情況下設置月,它不工作。
我設置錯了什麼?任何幫助將不勝感激。
private void showRoute(String route) {
try {
JSONObject jsonObject = new JSONObject(route);
String arrayData = jsonObject.getString("JsonData");
JSONArray jsonArray = new JSONArray(arrayData);
Log.d(TAG, "JSONArray" + ">>>>>>>>>>" + jsonArray);
for (int i = 467; i < jsonArray.length(); i++) {
int month=5;//set search condition, i want to show a list , it's month > 5
//here is my search condition
if (Integer.parseInt(jsonArray.getJSONObject(i).getString("STARTMONTH"))>=month) {
String EDUTITLE = jsonArray.getJSONObject(i).getString("EDUTITLE");
String STARTMONTH = jsonArray.getJSONObject(i).getString("STARTMONTH");
String STARTDAY = jsonArray.getJSONObject(i).getString("STARTDAY");
String STARTDATE = jsonArray.getJSONObject(i).getString("STARTDATE");
String SPONSER = jsonArray.getJSONObject(i).getString("SPONSER");
String EDUSCORE = jsonArray.getJSONObject(i).getString("EDUSCORE");
String EDUIN = jsonArray.getJSONObject(i).getString("EDUIN");
String HOLDER = jsonArray.getJSONObject(i).getString("HOLDER");
ActivityListItem listItem = new ActivityListItem(EDUTITLE, STARTMONTH, STARTDAY, STARTDATE, SPONSER, EDUSCORE, EDUIN, HOLDER);
arrayList.add(listItem);
}else {
recyclerView.setVisibility(View.GONE);
textForEmpty.setVisibility(View.VISIBLE);
}
//arrayListOrigin.add(listItem);
}
} catch (JSONException ex) {
ex.printStackTrace();
}
}
和另外一個問題,如果我的數據是467〜500,我的列表中將顯示467〜500由升轉跌,如果我想讓它顯示500〜467由升轉跌,我應該怎麼做更正確嗎?
我嘗試一些這樣的代碼:它顯示空
String month="5";
if (month.equals(jsonArray.getJSONObject(i).getString("STARTMONTH"))) {
other code...
}
,但如果我嘗試比較EDUIN這樣的:它的工作原理...
String eduin="0";
if (eduin.equals(jsonArray.getJSONObject(i).getString("EDUIN"))) {
other code...
}
我不明白這一點現在: (
你可以添加樣本json –