完全初學者在這裏。我有jQuery庫。我打電話給返回json的api。我想使用jquery庫中的parseJSON函數來解析它。簡單地說,我不知道如何去做。JSON解析與jquery
我可以找到jQuery庫中的函數,它看起來像這樣:
parseJSON: function(data) {
if (typeof data !== "string" || !data) {
return null;
}
// Make sure leading/trailing whitespace is removed (IE can't handle it)
data = jQuery.trim(data);
// Attempt to parse using the native JSON parser first
if (window.JSON && window.JSON.parse) {
return window.JSON.parse(data);
}
// Make sure the incoming data is actual JSON
// Logic borrowed from http://json.org/json2.js
if (rvalidchars.test(data.replace(rvalidescape, "@")
.replace(rvalidtokens, "]")
.replace(rvalidbraces, ""))) {
return (new Function("return " + data))();
}
jQuery.error("Invalid JSON: " + data);
},
我如何通過發送我的JSON?