jQstringify是使用jQuery實現的JSON.stringify(obj)方法
代碼如下:
<script type="text/javascript" src="http:///keleyi/pmedia/jquery/jquery-1.10.2.min.js"></script>
function jQstringify( obj ) {
var arr = [];
$.each( obj, function( key, val ) {
var next = key + ": ";
next += $.isPlainObject( val ) ? printObj( val ) : val;
arr.push( next );
});
return "{ " + arr.join( ", " ) + " }";
};
var student = new Object();
student.name = "";
student.age = "25";
student.location = "廣州";
var json = JSON.stringify(student);
document.writeln('JSON.stringify(student)結果:');
document.writeln(json);
var myStringify=jQstringify(student)
document.writeln('jQstringify(student)結果:');
document.writeln(myStringify)
執行結果如下:
結果是一樣的