I'm trying but not right, I wanted to put it in the created hand, as if I had already received my JSON file. I tried to put the JSON structure inside the JSonObject but it did not work.
I'm trying but not right, I wanted to put it in the created hand, as if I had already received my JSON file. I tried to put the JSON structure inside the JSonObject but it did not work.
If you pass your String in JSON format to your JSONObject object, you can do something like this:
try {
String stringJSON = "{interests : [{interestKey:Dogs}, {interestKey:Cats}]}";
JSONObject obj = new JSONObject(stringJSON);
List<String> list = new ArrayList<String>();
JSONArray array = obj.getJSONArray("interests");
for (int i = 0; i < array.length(); i++) {
list.add(array.getJSONObject(i).getString("interestKey"));
}
} catch (JSONException e) {
e.printStackTrace();
}
Source: Parsing JSON Object in Java