- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有以下 jQuery/JS 代码
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
<script>
$.getJSON("http://example/topics", {}, function(data){
console.log( data ); // display the JSON *data* in the web console
console.log( $.parseJSON(data) );
});
</script>
console.log(data) 在 firebug 控制台(firefox 插件)中显示 JSON 数据,但 console.log( $.parseJSON(data) ) 显示 <强>空。
可能的原因是什么。
我需要将 JSON 字符串转换为数组。
最佳答案
我认为是因为 $.getJSON
已经解析了数据。 data
是 Javascript 对象。
The
success
callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and parsed using the$.parseJSON()
method.
当然,如果您向我们展示输出,我们可以说更多,但通常,$.getJSON
已经解析了响应。
P.S.:我希望您在实际代码中使用正确的 URL。
关于jquery - 为什么 parseJSON 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6465468/
我正在 jsoning 一个 C# const 类,获取名称-值对。我需要在客户端通过字符串名称访问它们,例如 return $.parseJSON(constantClass).'property'
我在 ASP.NET Web 表单应用程序中有一个回调函数,我试图返回一些方便的 JSON,以便 javascript 函数管理数据。我能够发回包含所有数据的 JSON 字符串,但现在我尝试获取以下结
在一个js文件中,我有下面的代码。 用这个语法没问题 $(jQuery.parseJSON(category)).each(function() { $(selector).append($
我从 test.php 中的 mysql 查询得到一个数组 $rows =Array ( [0] => Array ( [name] => nikhil ) [1] => Array ( [name]
我正在尝试从我的 ERP 平台(用 C# 编写的 API)解析一些数据。当我尝试解析数据中包含的信息时,我得到了未定义的结果。我一直在寻找一些答案,我什至可以想出另一种方法来做到这一点: for(va
我正在尝试从 span 元素上的 html data 属性发送数据并使用 Ajax 接收它,然后使用 php 和 mysql 处理它并返回新的我在 html 中的数据属性的值,但我收到一个错误,提示“
有人可以向我解释一下为什么包含双引号字符串的 json 会破坏 $.parseJSON 吗? 这有效: [{"type":"message","content":{"user":"tomasa", "
我有一个很长的 json 数组,需要发送到 html5 移动应用程序并进行解析。整个数组大约有 700kb(压缩到 150kb),目前长度为 554976 个字符。但随着时间的推移它会增加。 使用 j
jsfiddle link var x = { "Item1" : 1, "Item2" : { "Item3" : 3 } } alert(JSON.s
我正在从 Web 服务获取 JSON。当我使用 jQuery.parseJSON 时,由于某种原因它是空的。这是 JSON 的示例(使用 JSON.stringify(msg) 获取) {"0":{"
我使用ajay从服务器获取一些JSON数据,通过将数组传递给PHP的json_enocode(),它返回一个有效的JSON(在许多在线JSON调试器上检查过)。但是 JS 的 $.parseJSON(
我一直在使用 jQuery 的 parseJSON 和 simplejson,但我似乎无法弄清楚为什么我无法打印或比较我的变量。 我知道我的 Python return 语句是正确的,因为如果不是正确
我从服务器获取此 JSON "{"name": "abcd,e"abc"ssfgh", "location": {"latitude": 21.1484436189,"longitude": 79.0
我试图用 jquery 显示 json 数组的内容,但它返回此错误: SyntaxError: JSON.parse: unexpected character at line 1 column 2
我正在尝试将字符串解析为对象。我查看了以下 jQueryparseJSON 文档 link我还包含了 jquery 库,所以我知道它不是那样的。 这是我到目前为止的代码 var str = "{'va
我遇到了一个更大的问题,并将其缩小到这个范围。 $.parseJSON() 无法正确解析从我的服务器返回的 JSON。 我相信它与类似的模式有关(我不确定这是否是 javascript 对象的正确术语
我得到一个表示 JSON 对象的字符串(根据 JSONLint,它是一个有效的 JSON 字符串)。 当我打电话时: console.log(JSON.parse(datasource_graphe_
我在用 jQuery parseJSON 函数做一些事情。 这是代码,它不起作用 var obj = $.parseJSON("{'w':'w-1'}"); alert(obj.w); 调试了一段时间
在我的 Firebug 中,我看到服务器响应: {"status":"Results Found","errorcode":"0","result":[{"name":"test","id":"1"}
我正在尝试使用 Google 图表 API 绘制折线图,并使用 PHP codeignitor 从 mySQL 数据库检索数据。 到目前为止,我能够检索数据,但我无法解析 Json 数据并将它们填
我是一名优秀的程序员,十分优秀!