JSON Stringify and Parse

Source: Internet
Author: User

Source: http://javascript.ruanyifeng.com/stdlib/date.html

    //Parse JSON can also pass in a method, basically and stringify almost, but in reverse order, pay attention to the return of key = "", basically return value is good//make a Test yourself better understandfunction f (key, value) {//Console.log (key); //Console.log (value);        if(Key = = ="") {            returnvalue; }        return{age: A        }; }    varO1 ={name:"keatkeat", array: ["a","b"]    }    varn \Json.parse (Json.stringify (O1), f);              Console.log (o); //The 2nd parameter array, you can filter out the attributes we want to specify for obj//if the 2nd argument is a function, it will be the object and array of the execution set, and the property will be ignored if the undefined is returned.//This key value loop includes the object (key= "", Value=object), an array (key= "", Value=array), each of the attributes within the object (Key=attr,value=value), each value in the array (key= 0, Value=value)//the value of return will continue to be returned to the ladder, for example, if you turn a string into a return object, it will also handle the object (so be aware of circular references)//If you are dealing with an object and it has the ToJSON method, it will be called to get return value (such as JS date with this method)//making a Test yourself is easy to understand. //the 3rd parameter can be a beautiful JSONjson.stringify (obj, function (key, value) {Console.log (key);        Console.log (value); //custom processing, you have to worry about this.        if(Value.tojson) {returnValue.tojson (); }        returnvalue; }, " "); Json.stringify (obj, ["onlythisattrwant"]," ");

JSON stringify and parse

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.