我有一个动态生成的页面,其中我希望使用静态JavaScript并将JSON字符串作为参数传递给它。我见过谷歌使用这种方法(参见Google's +1 Button: How do they do it?)。
但是,我应该如何从JavaScript中读取JSON字符串呢?
<html>
<head>
<script src="jquery-1.6.2.min.js"></script>
<script src="myscript.js">{"org": 10, "items":["one","two"]}</script>
</head>
<body>
Hello
</body>
</html>
在这个JavaScript中,我想使用HTML文档中的JSON参数{"org": 10, "items":["one","two"]}
。我不知道使用jQuery还是不使用它是最好的。
$(function() {
// read JSON
alert("the json is:")
})
https://stackoverflow.com/questions/7581133
复制相似问题