admin管理员组文章数量:1406052
I am seeing a strange issue when fetching a JSON object from a URL using Jquery $.ajax function.
I am using the following JQuery call to retrieve the JSON object:
1 $.ajax({
2 url: '/test/getjson',
3 success: function(data){
4 doSomething(data); //(breakpoint here)
5 },
6 error: function(x,y,z){
7 //error..
8 }
9 });
The URL '/test/getjson' returns the following JSON object (Here is what the response looks like in Firebug):
{
"rsp": {
"date": "1299195954782" ,
"type": "Type1" ,
"Main": {
"Category1" : {
"private" : "Y" ,
"properties" : {
"one" : {
"response" : "" ,
"text" : "label" ,
"type" : "property"
},
"two" : {
"options" : [
"1" ,
"2" ,
"3" ,
"4" ,
"5" ,
"6" ,
"7" ,
"8" ,
"9" ,
"10"
],
"response" : "1" ,
"text" : "label2" ,
"type" : "property2"
}
}
},
"username" : "spiderman"
}
}
}
Problem
The problem is that all arrays in the JSON object have extra values with keys 'remove' and '__proto__' after being parsed by JQuery (Firebug's Debugger viewing JSON data object, breakpoint at line 4 in the JS snippet above):
[JSON object as seen by Firebugs debugger]
And here is a closer look at the strange part of the JSON object:
[Closer look at the unknown data]
Thanks ahead everyone :)
I am seeing a strange issue when fetching a JSON object from a URL using Jquery $.ajax function.
I am using the following JQuery call to retrieve the JSON object:
1 $.ajax({
2 url: '/test/getjson',
3 success: function(data){
4 doSomething(data); //(breakpoint here)
5 },
6 error: function(x,y,z){
7 //error..
8 }
9 });
The URL '/test/getjson' returns the following JSON object (Here is what the response looks like in Firebug):
{
"rsp": {
"date": "1299195954782" ,
"type": "Type1" ,
"Main": {
"Category1" : {
"private" : "Y" ,
"properties" : {
"one" : {
"response" : "" ,
"text" : "label" ,
"type" : "property"
},
"two" : {
"options" : [
"1" ,
"2" ,
"3" ,
"4" ,
"5" ,
"6" ,
"7" ,
"8" ,
"9" ,
"10"
],
"response" : "1" ,
"text" : "label2" ,
"type" : "property2"
}
}
},
"username" : "spiderman"
}
}
}
Problem
The problem is that all arrays in the JSON object have extra values with keys 'remove' and '__proto__' after being parsed by JQuery (Firebug's Debugger viewing JSON data object, breakpoint at line 4 in the JS snippet above):
[JSON object as seen by Firebugs debugger]
And here is a closer look at the strange part of the JSON object:
[Closer look at the unknown data]
Thanks ahead everyone :)
Share edited Mar 5, 2011 at 17:06 Oleg 222k35 gold badges413 silver badges812 bronze badges asked Mar 4, 2011 at 18:43 tjmehtatjmehta 31.3k4 gold badges24 silver badges18 bronze badges1 Answer
Reset to default 8Stop using "for ... in" to iterate over arrays, and use an index variable.
for (var i = 0; i < theArray.length; ++i) {
var element = theArray[i];
// ...
}
Those object properties are there thanks to the JavaScript runtime in your browser. I'm not sure why they'd cause you any trouble because they should not be iterable. Perhaps if you showed the actual code that you've got to process the ajax response, the issue might bee more clear.
本文标签: javascriptJQuery JSON parsingAJAX issue (39remove39 and 39proto39 keys in arrays)Stack Overflow
版权声明:本文标题:javascript - JQuery JSON parsingAJAX issue ('remove' and '__proto__' keys in arrays?) - Stack Ov 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744949708a2634006.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论