Issue
I want to get particular user data from PHP MySql in Android. Here is my URL (xxx//xxxxxxx/client_vendor_mgmt/subcategory.php?cat_id=2) and here is the URL data in json:
[
{
"subcat_id": "1",
"subcat_code": "cell1",
"subcat_name": "cell",
"cat_id": "2",
"subcat_created_date": "0000-00-00",
"subcat_isactive": "Y",
"subcat_updated_date": "0000-00-00"
},
{
"subcat_id": "2",
"subcat_code": "cell2",
"subcat_name": "tv",
"cat_id": "2",
"subcat_created_date": "0000-00-00",
"subcat_isactive": "Y",
"subcat_updated_date": "0000-00-00"
}
]
I want to get all the record of "cat_id":"2". How can I get this record?
Solution
Here is the code
try {
JSONArray array=new JSONArray("yourJsonString");
JSONArray sortedArray = new JSONArray();
for(int i=0;i<array.length();i++)
{
JSONObject obj=array.getJSONObject(i);
if(obj.getString("cat_id").equalsIgnoreCase("2"))
{
sortedArray.put(obj);
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Answered By - Rohan Pawar Answer Checked By - Senaida (PHPFixing Volunteer)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.