1 <Scriptsrc= "Http://apps.bdimg.com/libs/jquery/2.1.4/jquery.js"></Script>2 <Script>3 //JSON extension Methods4 if (!Object.prototype.forEach) {5 Object.prototype.forEach= function(FN) {6 Try {7 for (varKeyinch This) {8 //determines whether a property is a property of the object itself. 9 if ( This. hasOwnProperty (Key)) {Ten Fn.call ( This, Key, This[key]); One //fn.apply (this, [key, This[key]); A } - } - } Catch(e) { the Throwe; - } - } - } + </Script>
JSON extension
<Script> varStringeap= '{"name": "Xiaoming", "Age": ""} "'; varJsoneap={name:'Xiao Ming', Age:' -' }; //JSON Delete Deletejsoneap["name"];//or delete jsoneap.name; //JSON Add modificationJsoneap.name= "Xiao Wang";//or jsoneap["name"]= "Xiao Wang " //determine if the key exists in the JSONConsole.log (Jsoneap.hasownproperty ("name")); //JS processing JSON mode //go to standard format JSON varData=Json.parse (STRINGEAP); //JQ mode var dat= $.parsejson (stringeap) vardata1=Eval ("(" +Stringeap+ ")"); //go to JSON string varStringData=json.stringify (JSONEAP); Jsoneap.foreach (function(key, value) {Console.log (key, value); }); </Script>
JSON format processing and extension