<!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