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