During the development process, if you want to transfer a small number of parameters to the front and backend, you can directly use the data function of ajax, pass it in json format, and use the background Request. However, sometimes, you need to pass multiple parameters, so the background
It is troublesome to request multiple requests when accepting. At this time, it must be passed in the form of a class or a collection.
For example: the frontend passes JSON objects in class format:
var jsonUserInfo = "{"TUserName":"" userName "","TInterest":"" interest "","TSex":"" sex "","TCity":"" city "","TDetail ":"" detail ""}";
If the jsonUserInfo is spelled out without escape symbols, var jsonArrayFinal = JSON.stringify(jsonArray); needs to be converted before passing.
var a={"name":"tom","sex":"male","age":"24"};
var b='{"name":"Mike","sex ":"Female","age":"29"}';
In advanced browsers such as Firefox, chrome, opera, safari, ie9, ie8, etc., you can directly use the stringify() and parse() methods of the JSON object.
JSON.stringify(obj) converts JSON to string. JSON.parse(string) converts the string into JSON format;
var a={"name":"tom","sex":"male","age":"24"};
var b='{ "name":"Mike","sex":"女","age":"29"}';var aToStr=JSON.stringify(a);
var bToObj=JSON.parse(b );alert(typeof(aToStr)); //string
alert(typeof(bToObj)); //object
JSON.stringify()
ie8 (compatibility mode), ie7 and ie6 do not have JSON objects, but
http://www.json.org/js.html
ie8 (compatibility mode), ie7 and ie6 can use eval() to convert strings into JSON objects,
var c='{"name":"Mike","sex":"女","age":"29"}'; var cToObj=eval("(" c ")") ;
alert(typeof(cToObj));jQuery also has a method for converting strings to JSON format, jQuery.parseJSON(json), which accepts a standard format JSON string and returns a parsed JavaScript (JSON) object. Of course, if you are interested, you can encapsulate a jQuery extension yourself. jQuery.stringifyJSON(obj) converts JSON into a string.