我使用以下JQuery代码行:
$.get('/ajax/buy', {'categoryname':chosenSelected}, function(data) {
data = JSON.parse(data);
...
Run Code Online (Sandbox Code Playgroud)
但是,当在IE7上运行它时,我收到以下错误消息:JSON undefined:.
如何使用与IE7(以及所有主流浏览器)兼容的解析器?
我正在尝试从中提取数据的网页.通过查看页面Source中的HTML,我可以在脚本标记中找到我感兴趣的数据.它看起来如下:
<html>
<script type="text/javascript">
window.gon = {};
gon.default_profile_mode = false;
gon.user = null;
gon.product = "shoes";
gon.books_jsonarray = [
{
"title": "Little Sun",
"authors": [
"John Smith"
],
edition: 2,
year: 2009
},
{
"title": "Little Prairie",
"authors": [
"John Smith"
],
edition: 3,
year: 2009
},
{
"title": "Little World",
"authors": [
"John Smith",
"Mary Neil",
"Carla Brummer"
],
edition: 3,
year: 2014
}
];
</script>
</html>
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,使用其URL调用网页,然后从JavaScript中检索'gon'变量并将其存储在C#变量中.换句话说,在C#中,我希望有一个数据结构(例如字典),它将保存'gon'的值.
我已经尝试过研究如何通过C#WebBrowser获取JavaScript中定义的变量,这就是我发现的:
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Net;
using System.Runtime.InteropServices; …Run Code Online (Sandbox Code Playgroud)