0
Q
沒有每個功能
A
回答
2
爲此,您可能需要添加JSON lib中舊版本的瀏覽器:
var json = JSON.parse('{"baseUrl":"\/","success":true}');
// or
json = {"baseUrl":"\/","success":true};
alert(json.success)
//or
alert (json['success'])
在jQuery的AJAX可以使用的dataType json
。 這將直接解析代碼,這樣你會
/* Ajax Get-Request */
$.ajax({
type : 'get',
url : "myurl.html",
dataType : 'json',
success : function (response)
{
alert (response.success)
alert (response['success'])
},
// Internal Server Error/Timeout
error : function (XMLHttpRequest, textStatus, errorThrown)
{
alert ("Error \n" + textStatus);
}
});
0
這裏亞去。
var getJsonProperty = (function(){
var hasJson = (window.JSON && JSON.parse && JSON.parse.call);
return hasJson ? function (jsonString, property) {
return JSON.parse(jsonString)[property];
} : function (jsonString, property) {
return new Function("return ("+jsonString+")['"+property+"'];")();
}
})();
alert (getJsonProperty('{"baseUrl":"\/","success":true}', 'success'));
// shows `true`
相關問題
- 1. 每個功能
- 2. 沒有一個組功能
- 3. 沒有一個組功能
- 4. Specflow:每個功能
- 5. 在每個功能
- 6. 每個引腳有不同的功能?
- 7. Ajax沒有功能
- 8. 沒有「每個」
- 9. tipr.js瞭解每個功能
- 10. 每個功能的jquery
- 11. 功能爲每個元素
- 12. jQuery的 - 每個功能
- 13. 爲每個功能jquery
- 14. VB.NET功能uppercasing每個字
- 15. 每個功能模塊
- 16. jQuery的每個功能IE7
- 17. 每個功能 - 多選
- 18. jQuery的每個功能
- 19. 如何從每個功能
- 20. 有沒有地圖功能?
- 21. 功能沒有定義,返回一個匿名功能
- 22. SQL沒有一個組功能錯誤
- 23. MySQL沒有一個weekyear功能
- 24. 沒有一個組羣功能
- 25. 有沒有辦法將這3個功能簡化爲1個功能?
- 26. JQuery的功能沒有得到應用到每一個DIV以外所有的
- 27. Sharepoint 1功能部署所有列表或每個列表1個功能
- 28. 調用JavaScript沒有功能?
- 29. 功能沒有返回龍
- 30. 功能上沒有的NodeJS
只有當您從可信來源獲取JSON時才能執行此操作。 – 2010-07-14 06:45:24
有沒有人真的從他們認爲可能對腳本進行腳本注入攻擊的源中獲取JSON?無論如何,這是與'JSON.parse'預兼容的,這很重要。它比替代方法'eval'更安全,因爲它不在本地函數範圍內執行。如果您願意,您總是可以解析惡意內容的字符串,但在許多(大多數?)實際案例中,您將從可信來源獲取內容。 – 2010-07-14 07:08:10