admin管理员组文章数量:1390775
I get a JSON file via jQuery $.getJSON(url, function(data) {
...
and want to parse it with either
var obj = JSON.parse(data);
or
var obj = jQuery.parseJSON(data);
The first line gives me "syntax error" (using IE8, should support JSON.parse
), the second gives me "'center' is null or not an object".
This is the valid JSON file I'm using:
{
"center":{"lat":"51.99637","lon":"13.07520"},
"locations":
[
{ "name":"a string","info":"another string" },
... some more here ...
]
}
I'm not too familiar with Javascript. What am I doing wrong?
If I use a simple JSON array (= just the content of locations) I get valid data with $.each
.
Do I have to do something with data before I can use JSON.parse on it?
I get a JSON file via jQuery $.getJSON(url, function(data) {
...
and want to parse it with either
var obj = JSON.parse(data);
or
var obj = jQuery.parseJSON(data);
The first line gives me "syntax error" (using IE8, should support JSON.parse
), the second gives me "'center' is null or not an object".
This is the valid JSON file I'm using:
{
"center":{"lat":"51.99637","lon":"13.07520"},
"locations":
[
{ "name":"a string","info":"another string" },
... some more here ...
]
}
I'm not too familiar with Javascript. What am I doing wrong?
If I use a simple JSON array (= just the content of locations) I get valid data with $.each
.
Do I have to do something with data before I can use JSON.parse on it?
2 Answers
Reset to default 5The problem is that the name of the function is slightly misleading : it doesn't give you JSON
but already a parsed object. What it does is fetch some JSON
and parse it for you.
data
is a plain javascript object, you don't need to parse it.
$.getJSON will parse the data for you - you don't need to parse it manually after the fact.
本文标签: javascriptJSONparse() not working on jQuery data objectStack Overflow
版权声明:本文标题:javascript - JSON.parse() not working on jQuery data object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744668403a2618672.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论