JSON serialization-complex simplification

Source: Internet
Author: User

<!DOCTYPE HTML><HTMLLang= "en"><Head>    <MetaCharSet= "UTF-8">    <title>Josn Object</title>    <Script>        var Book={title:"PHP Best Practices", authors:['Jack'], Edition:3, Year: .        }; //json.stringify () has three parameters, namely, a JSON object, a filter (which can be an array or function), whether to retain indentation in the JOSN string (this parameter is not very important to ignore)        varJsontext=json.stringify (book); varJsonText1=json.stringify (book,["title"," Year"]); varjsonText2=json.stringify (book,function(key,value) {Switch(key) { Case "title":                    return "Java from getting started to mastering";  Case " Year":                    return 2018;  Case "Edition":                    returnundefined; default:                    returnvalue;        }        }); Console.log (jsontext);//{"title": "PHP Best Practices", "authors": ["Jack"], "edition": 3, "Year":Console.log (JSONTEXT1);//{"title": "PHP Best Practices", "Year":}Console.log (JSONTEXT2);//{"title": "Java from getting started to mastering", "Authors": ["Jack"], "Year": 2018}        //Json.parse (ARG1,ARG2) can accept 2 parameters one is a JSON string, one is a filter function        varJsonobject=Json.parse (Jsontext); varJsonObject1=Json.parse (Jsontext,function(key,value) {if(Key===" Year"){                return 2019            }Else if(Key==="title"){                return "JavaScript from Getting started to mastering"; }Else{                returnvalue;        }        }); Console.log (jsonobject);//Object {title: "PHP Best Practices", Authors:array (1), Edition:3, year:2017}Console.log (jsonObject1);//Object {title: "JavaScript from Beginner to proficient", Authors:array (1), Edition:3, year:2019}            </Script></Head><Body></Body></HTML>

JSON serialization-complex simplification

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.

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.