JQ implementation Json.stringify (obj) method

Source: Internet
Author: User

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

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.