JQ implementation Json.stringify (obj) method

Source: Internet
Author: User

Tags: object   text   qstring   print   script    new    code    plain   each   

Jqstringify is the json.stringify (obj) method implemented using jquery

Code as follows:
<script type= "Text/javascript" src= "/HTTP/ Keleyi.com/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 = "Collayi";
Student.age = "25";
Student.location = "Guangzhou";

var json = json.stringify (student);
Document.writeln (' json.stringify (student) results: ');
Document.writeln (JSON);

var mystringify=jqstringify (student)
Document.writeln (' jqstringify (student) Result: ');
Document.writeln (mystringify)

Executes the result as follows:
Json.stringify (Student) Result: {"name": "Collayi", "Age": "25", " Location ":" Guangzhou "} jqstringify (Student) Result: {name: Collayi, age:25, location: Guangzhou} 

The result is the same

JQ implementation Json.stringify (obj) method

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: