Reputation: 79
this is my first attempt at using a JSON file sourced from a local directory on an android device. Now I can parse information fine. My only issue is selecting sub categories i.e if one section contains the Series "x1" I would just want to list the results that contain series "x1". Is there a way to do this? Id like to get the selectors done first before making it look "fancy" :) any help would be great. A snippet of my JSON is below:
[
{
"name": "Test",
"value": "value from first field",
"Series": "x2"
},
{
"Batch": "0001",
"character": "Orange",
"Series": "x1",
"image": "https://.png",
"name": "Xr122",
"value": "Figure"
}
]
Now for my code it reads the following:
ArrayList<String> fields = new ArrayList<String>();
for (int index = 0; index < jsonArray.length(); index++) {
//Set both values into the listview
JSONObject jsonObject = jsonArray.getJSONObject(index);
fields.add(jsonObject.getString("name") + " - " + jsonObject.getString("value"));
}
I just don't know where to begin when selecting certain factors when searching. If game series equals "x1" then show etc etc. A point in the right direction would be great. I have a list of over 500 results and thought this would be a much quicker way to sort he results instead of writing a new json file also would allow for custom searches. This is my first try with this so any tips would be great.
Upvotes: 0
Views: 58
Reputation: 319
you can try this but it may take some time:
ArrayList<String> fields = new ArrayList<String>();
for (int index = 0; index < jsonArray.length(); index++) {
//Set both values into the listview
JSONObject jsonObject = jsonArray.getJSONObject(index);
String series = jsonObject.getString("series");
if(series.equals("x1")){
fields.add(jsonObject.getString("name") + " - " + jsonObject.getString("value"));
}
}
Upvotes: 3