I have a JSON type string
{ "countries": [ [19,"Австралия"], [20,"Австрия"], [5,"Азербайджан"], [21,"Албания"], [22,"Алжир"], [23,"Американское Самоа"] ] } How to get this string in a String array?
Not very clear what you need, the following code parses and puts geographic objects in an array of strings:
String json = "{\"countries\":[[19,\"Австралия\"],[20,\"Австрия\"],[5,\"Азербайджан\"],[21,\"Албания\"],[22,\"Алжир\"],[23,\"Американское Самоа\"]]}"; ArrayList<String> result = new ArrayList<>(); try { JSONObject rootJson = new JSONObject(new JSONTokener(json)); JSONArray countriesJson = rootJson.getJSONArray("countries"); for (int i = 0; i < countriesJson.length(); i++) { JSONArray countryJson = countriesJson.getJSONArray(i); result.add(countryJson.getString(1)); } } catch (JSONException e) { e.printStackTrace(); } Log.d("TAG", result.toString()); //[Австралия, Австрия, Азербайджан, Албания, Алжир, Американское Самоа] Source: https://ru.stackoverflow.com/questions/606079/
All Articles
jsonquotes, and changing quotes inside from"to\". - pank