JS uses JSON for parameter instance analysis and json instance analysis
This example describes how to use JSON as a parameter in JS. We will share this with you for your reference. The details are as follows:
Function getAjaxData (urlstr, callback_func, options) {var myurl = AJAX_HEADER + urlstr + AJAX_TAIL; var isAsync = true; // set var nTimeout = AJAX_TIMEOUT when initializing the synchronization attribute; // var errorCallback = null for data timeout during initialization; // use the JSON object options to modify the default initialized attribute, so that a parameter can set multiple attributes if (options) {if (options. sync) // The parameter sync is the JSON object {isAsync = (options. sync = true )? False: true;} if (options. timeout) {nTimeout = parseInt (options. timeout); if (isNaN (nTimeout) nTimeout = AJAX_TIMEOUT;} errorCallback = options. errorCB;} if ($. browser. mozilla) {try {// netscape. security. privilegeManager. enablePrivilege ("UniversalBrowserRead");} catch (exception) {log. error (exception) ;}}$. ajax ({async: isAsync, // cache: false, type: "GET", timeout: nTimeout, url: myurl, // DataType: ($. browser. msie )? "Text": "xml", error: function (XMLHttpRequest, textStatus) {try {if (jQuery. isFunction (errorCallback) {errorCallback (XMLHttpRequest, textStatus);} log. error ("MAIN: getAjaxData (" + myurl + ") error. "); log. error ("MAIN: XMLHttpRequest. readyState = "+ XMLHttpRequest. readyState); log. error ("MAIN: XMLHttpRequest. status = "+ XMLHttpRequest. status); log. error ("MAIN: textStatus" + textStatus );} Catch (exception) {log. error (exception) ;}, success: function (data) {log. debug ("MAIN: getAjaxData (" + myurl + ") sucess. "); log. trace (data); var xml; if (typeof data = "string" | typeof data = "number") {if (! Window. activeXObject) {var parser = new DOMParser (); xml = parser. parseFromString (data, "text/xml");} else {// IE xml = new ActiveXObject ("Microsoft. XMLDOM "); xml. async = false; xml. loadXML (data) ;}} else {xml = data;} if (typeof callback_func = "function") {callback_func ($ (xml);} else {log. error ("callback_func is undefined or not a function") ;}});} getAjaxData ("api/monitoring/status", function ($ xml) {var wlan_ret = xml2object ($ xml); if (wlan_ret.type = "response") {monitoring_status = wlan_ret.response; setcurr#userhtml () ;}}, {sync: true // transmit multiple data through JSON to prevent data redundancy, which is similar to configuration information });
The following is a simple example:
function testJSON(JSON){ alert(JSON.name); alert(JSON.age); alert(JSON.id);}testJSON({name:"huangbiao", "age":23, "id":1});
PS: I recommend several json online tools for you here. I believe they can be used in future development:
Online JSON code verification, validation, beautification, and formatting tools:
Http://tools.jb51.net/code/json
JSON online formatting tool:
Http://tools.jb51.net/code/jsonformat
Online XML/JSON conversion tools:
Http://tools.jb51.net/code/xmljson
Json code online formatting/beautification/compression/editing/conversion tools:
Http://tools.jb51.net/code/jsoncodeformat
C language style/HTML/CSS/json code formatting and beautification tools:
Http://tools.jb51.net/code/ccode_html_css_json