Parses JSON strings and json strings.
Import java. util. arrayList; import java. util. list; import org. json. JSONArray; import org. json. JSONObject; public class JSONUtils {// read the JSON String and return the List <String> String List public static List <String> parseCityJSONStr (String str) {List <String> list = new ArrayList <String> (); JSONObject jsonObject; try {// JSON from very {} indicates JSONObject // create JSONObject jsonObject JSONObject = new JSONObject (str) here; // according to the content (key) before the colon in the json object) get the content after the colon (values) // The content following it is a JSON array (JSONArray jsonArray = jsonObject. getJSONArray ("citys"); // traverses the data in JSONArray for (int I = 0; I <jsonArray. length (); I ++) {String city = (String) jsonArray. get (I); list. add (city) ;}} catch (Exception e) {e. printStackTrace ();} return list ;}}