I. Conversion of JSON objects to JSON strings
1.How the jquery plugin supports conversion :
$.parsejson (JSONSTR); Jquery.parsejson (JSONSTR), you can convert a JSON string into a JSON object
2. browser supported conversion Mode (FIREFOX,CHROME,OPERA,SAFARI,IE9,IE8) and other browsers:
Json.stringify (obj) converts the JSON to a string. Json.parse (String) to convert the string to JSON format;
var a={"name": "Tom", "Sex": "Male", "Age": "24"};
var b= ' {' name ': ' Mike ', ' sex ': ' Female ', ' age ': ' 29 '} ';
var atostr=json.stringify (a);
var btoobj=json.parse (b);
Alert (typeof (Atostr)); String
Alert (typeof (Btoobj));//object
3.how JavaScript supports conversion :
Eval (' (' + jsonstr + ') '); You can convert a JSON string to a JSON object, noting that you need to wrap a pair of parentheses outside the JSON character
Note: IE8 (compatibility mode), IE7 and IE6 can also use eval () to convert strings to JSON objects, but these methods are not recommended, which is unsafe for eval to execute an expression in a JSON string.
4.JSON Official Conversion Mode :
http://www.json.org/provides a json.js so that IE8 (compatibility mode), IE7 and IE6 can support JSON objects as well as their stringify () and Parse () methods;
Can get this JS on Https://github.com/douglascrockford/JSON-js, generally now use json2.js.
Ii. conversion of JSON strings to Java objects
1. Convert the list of Java objects to an array of JSON objects and move to a string
Jsonarray array = jsonarray.fromobject(list);
Stringjsonstr = Array.tostring ();
2. Converting Java objects to JSON objects and converting them into strings
Jsonobject object =jsonobject.fromobject(user);
Log4jInit.ysulogger.debug (Object.ToString ());
3. Convert the JSON string to an array of Java objects
Jsonarray JSON =jsonarray.fromobject (USERSTR);//userstr is a JSON string
List<user>users= (list<user>)jsonarray.tocollection(JSON, user.class);
4. Convert the JSON string to a Java object
Jsonobjectjsonobject = Jsonobject.fromobject (JSONSTR);
User user= (user)Jsonobject.tobean(object,user.class);
Conversion of JSON objects to JSON strings, JSON strings to Java objects