呵呵,正文,感觉周同学的支持.
JSON => String:
- jsonToString: function(obj){
- var THIS = this;
- switch(typeof(obj)){
- case 'string':
- return '"' + obj.replace(/(["\\])/g, '\\$1') + '"';
- case 'array':
- return '[' + obj.map(THIS.jsonToString).join(',') + ']';
- case 'object':
- if(obj instanceof Array){
- var strArr = [];
- var len = obj.length;
- for(var i=0; i
- strArr.push(THIS.jsonToString(obj[i]));
- }
- return '[' + strArr.join(',') + ']';
- }else if(obj==null){
- return 'null';
-
- }else{
- var string = [];
- for (var property in obj) string.push(THIS.jsonToString(property) + ':' + THIS.jsonToString(obj[property]));
- return '{' + string.join(',') + '}';
- }
- case 'number':
- return obj;
- case false:
- return obj;
- }
- },
String => JSON
- stringToJSON: function(obj){
- return eval('(' + obj + ')');
- },
var k_data =
{
result:200,
msg:20,
rows:
[
{item:"path.encoder.@dfds", value:"222333" },
{item:"newyork", value:"555666" }
]
};
$.ajax(
{ type:"POST", url:"/conf/delete.act" , async:true, dataType: "json", timeout: 30000,cache: false, data:jsonToString( k_data ),
complete:function( data )
{
},
success:function( data )
{
},
error:function( XMLHttpRequest, textStatus, errorThrown )
{
}
}
);