- Prototype 教程
- 原型 — 主頁
- 原型 — 簡要概述
- Prototype — 有用功能
- Prototype — 實用方法
- Prototype — 元素物件
- Prototype — 數字處理
- Prototype — 字串處理
- Prototype — 陣列處理
- Prototype — 雜湊處理
- Prototype — 基本物件
- Prototype — 模板化
- Prototype — 列舉
- Prototype — 事件處理
- Prototype — 表單管理
- Prototype — JSON 支援
- Prototype — AJAX 支援
- Prototype — 表示範圍
- Prototype — 週期性執行
- Prototype 實用資源
- Prototype — 快速指南
- Prototype — 實用資源
- Prototype — 討論
原型—isJSON() 方法
此方法透過使用正則表示式檢查字串是否是有效的 JSON。此安全方法在內部呼叫。
語法
string.isJSON();
返回值
返回布林值。
示例
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function showResult() {
var str = "something";
alert("something.isJSON() : " + str.isJSON());
var str = "\"something\"";
alert("\"something\" : " + str.isJSON());
var str = "{ foo: 42 }";
alert("{ foo: 42 } : " + str.isJSON());
var str = "{ \"foo\": 42 }";
alert("{ \"foo\": 42 } : " + str.isJSON());
}
</script>
</head>
<body>
<p>Click the button to see the result.</p>
<br />
<br />
<input type = "button" value = "Result" onclick = "showResult();"/>
</body>
</html>
輸出
prototype_string_processing.htm
廣告