/**
* Add a serialization method to JSON data,
* Primarily for IE6, 7 browsers that do not support JSON objects
*/
var xue = Xue | | {};
Xue.json = Xue.json | | {};
xue.json.stringify = function (obj) {
If the ie8+ browser (Ff,chrome,safari supports JSON objects), use Json.stringify () to serialize
if (window. JSON) {
return json.stringify (obj);
}
var t = typeof (obj);
if (t! = "Object" | | obj = = = null) {
Simple data type
if (t = = "string") obj = ' "' + obj + '";
return String (obj);
} else {
Recurse Array or Object
var n, V, json = [],
arr = (obj && obj.constructor = = Array);
Fix.
var self = Arguments.callee;
for (n in obj) {
v = obj[n];
t = typeof (V);
if (Obj.hasownproperty (n)) {
if (t = = "string") v = ' "' + V + '";
else if (t = = "Object" && v!== null)
v = jquery.stringify (v);
v = self (v);
Json.push (arr? "": ' "' + N + '": ') + String (v));
}
}
Return (arr?) "[": "{") + String (JSON) + (arr. "]": "}");
}
};
/*
* Method:parse (JSON string)
* Return:js Native value
*/
Xue.json.parse = function (jsonstring) {
if (window. JSON) {
return window. Json.parse (s);
}
Using the Parsejson (s) method of jquery
Return $.parsejson (jsonstring);
};
How to use:
var _json = {
"js_58": [' a ', ' B '],
"js_39": [' a ', ' B ', ' C '],
"js_68": [' a ']
}
To serialize a JSON object _json:
Xue.json.stringify (_json);
Note: If the AJAX parameter is a JSON data object, it is best to serialize the JSON object first
JS implementation of JSON data serialization (compatible with IE6 or more browsers)