JSON's simple use _ parse the JSON data from the foreground

Source: Internet
Author: User

1  PackageCn.rocker.json;2 3 Importorg.junit.Test;4 5 ImportNet.sf.json.JSONArray;6 ImportNet.sf.json.JSONObject;7 8 /**9 * @ClassName: ParsejsonfromfrontTen * @Description: Parse JSON from reception One  * @author the A * @date March 28, 2018 morning 10:47:01 -  */ -  Public classParsejsonfromfront { the  - @Test -      Public voidTest () { -         //the JSON received +String result = "[{\" username\ ": \" Your name\ ", \" user_json\ ": {\" username\ ": \" Your name\ ", \" nickname\ ": \" Your nickname \"}}]"; -  +         //to generate a JSON object from a string A         //convert to Jsonarray object using Jsonarray.fromobject (Result) in the form of an array at         //If a JSON object is converted to a Jsonobject object using Jsonobject.fromobject (Result) -Jsonarray Jsonarray =jsonarray.fromobject (result); -Jsonobject jsonobject = jsonarray.getjsonobject (0); -Jsonobject User_json = Jsonobject.getjsonobject ("User_json"); -  -         //value based on key value inString username = user_json.getstring ("username"); -String nickname = user_json.getstring ("nickname"); toSystem.out.println ("username =" + username + ":" + "nickname =" +nickname); +     } -  the}

JSON's simple use _ parse the JSON data from the foreground

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.