0
我正在學習JSON。我只寫了一個簡單的代碼,它不起作用,點擊按鈕時也不會出現任何錯誤。所以請幫我抓住錯誤。這裏是我的HTML。關於javascript和JSON的遇到錯誤
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript" language="javascript">
function GetJSON()
{
alert("pp");
var moviereviewtext = "{"title": "Friday the 13th", "year": 1980, "reviews":
[{"reviewer": "Pam", "stars": 3, "text": "Pretty good, but could have used more Jason"},
{"reviewer": "Alice", "stars": 4, "text": "The end was good, but a little unsettling"}]}";
var jsonobj = eval("(" + moviereviewtext + ")");
var reviewername = jsonobj.reviews[0].reviewer;
var numberstars = jsonobj.reviews[0].stars;
var reviewerthoughts = jsonobj.reviews[0].text;
alert(reviewername);
alert(numberstars);
alert(reviewerthoughts);
}
</script>
</head>
<body >
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="GetJSON();return false;" />
</form>
</body>
</html>
感謝您的努力,但沒有運氣.....仍然無法正常工作。 – Thomas 2011-04-22 15:51:12