I want to get the object of jsonarray if the attribute values are matched from jsonarray. Below code is good to get the attribute value by checking the list one by one.
JSONParser parser1 = new JSONParser();
JSONArray array = (JSONArray)parser1.parse("[{\"user_id\": 1,\"Name\":\"Andrew\"}, {\"user_i\": 1}, {\"user\": 1}]");
for (int i =0; i<array.size();i++){
System.out.println(((JSONObject)array.get(i)).get("Name"));
}
However, I want to get the index (list) i.e. {\"user_id\": 1,\"Name\":\"Andrew\"} when attribute values matches. something like
System.out.println(((JSONObject)array.get("Name")).get(i));
Can anyone please suggest me how to achieve this?
{\"user_id\": 1,\"Name\":\"Andrew\"}" An index is a number.{\"user_id\": 1,\"Name\":\"Andrew\"}isn't a number. What is it you're really looking for...?(JSONObject)array.get(i)and callget("Name")etc. on that? If the values match your requirements you found the json object you need and can keep working with it.