Reputation: 604
I am trying to search from JSON code that has been received beforehand..
I was wondering are there any efficient way to search specific object? Or should i use straight forward search like looping and if statement?
I have parsing the JSON successfully, and it stored in my String variable.. The JSON contains Array of Objects..
Now i want to search for specific ObjectName and get the Whole Objects.. The JSON will be like
[
{
"name":"blank",
"date":"2014-06-05T00:44:30Z",
"boolean":null,
},
{
"name":"hello",
"date":"2013-05-04T00:43:20Z",
"boolean":null,
}
]
I want to search for name = "hello" and get the last Array returned
Can anyone show me how?
Thanks a lot!
Upvotes: 3
Views: 9153
Reputation: 305
Try to use a web server with (PHP) and set your search element in GET like this.
Then the php search function will give you the full Json needed to your search. Also you can set pagination for this search like this.
Upvotes: 0
Reputation: 1
For big data you can't use search in every element imagin you have a 50K user you can't search in every 50k title to found your element I advise you to the backend - Web Developer - do this it will be easier to you and more faster how you can do this? You just need a space to pass search text in JSON Url then post it and retrieve searched data from him
Upvotes: 0
Reputation: 1957
You can use something like this:
String name;
JSONObject searchObject;
JSONArray array = new JSONArray(yourJsonString);
for (int i = 0; i < array.length(); i++) {
JSONObject currObject = array.getJSONObject(i);
name = currObject.getString("name");
if(name == "hello")
{
searchObject = currObject
}
}
return searchObject
Upvotes: 7