Parses JSON strings and json strings.

Source: Internet
Author: User

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 ;}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.