I am completely stuck on this and need help.
I need to get the value if another value is equal to something.
Lets say my array is:
"people":[
{"name": "David", "age": "30"},
{"name": "Bob", "age": "20"},
{"name": "Bill", "age": "30"}
]
I need to return the age if the name is lets say Bob. I have attempted to do it this way but to no avail.
String People = jsonPart.getString("people");
JSONArray arr = new JSONArray(People);
for (int h = 0; h < arr.length(); h++) {
JSONObject jsonPart = arr.getJSONObject(h);
String name = jsonPart.getString("name");
if (name == "Bob") {
String age = jsonPart.getString("age");
break;
}
}