Из конечной точки "test
" я возвращаю JSONObject
:
@POST("/test")
@PermitAll
public JSONObject test(String name) {
JSONObject jsonval=new JSONObject();
json.put("key1",true);
json.put("key2","test");
return json;
}
в методе, который проверяет возвращаемое значение, я хочу найти значение "key1".
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String json = null;
String res = "";
while ((res = in.readLine()) != null) {
json += res + "\n";
}
in.close();
if (jsonData has key1 with value true){
//do sth
}
else{
//do sth else
}
Как я могу разобрать возвращенный JSONObject?