jQuery.parseJSON( json )



jQuery.parseJSON( json )


Passing in a malformed JSON string may result in an exception being thrown. For example, the following are all malformed JSON strings:
{test: 1} (test does not have double quotes around it).
{'test': 1} ('test' is using single quotes instead of double quotes).


Additionally if you pass in nothing, an empty string, null, or undefined, 'null' will be returned from parseJSON. Where the browser provides a native implementation of JSON.parse, jQuery uses it to parse the string. For details on the JSON format, see http://json.org/.




翻譯:
jQuery.parseJSON( json )
傳入格式有誤的 JSON 字符串可能導致拋出異常。例如,下面這些 JSON 字符串格式都不對:
{test: 1} (test 沒有使用雙引號包裹).
{'test': 1} ('test' 用了單引號而不是雙引號包裹).
另外,如果你什麼都不傳入,或者傳入空字符串、null、undefined 等,parseJSON 都會返回 null 。如果瀏覽器原生實現了 JSON.parse, jQuery 則會使用它來解析字符串。更多關於JSON格式的細節請參考 http://json.org/ 







發佈了51 篇原創文章 · 獲贊 6 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章