开发者

eval json data get different length in IE and firefox

开发者 https://www.devze.com 2023-03-20 08:44 出处:网络
I got json data from the server by ajax: request.responseText=[{name:xxx},{name:xxx},{name:xx}]. Then I use the

I got json data from the server by ajax:

request.responseText=[{name:xxx},{name:xxx},{name:xx}].

Then I use the

var data=eval(request.responseText);

alert(data.length);

In IE,it is "4",while in Firefox it is "3".

Use the IE debugger I found that the element in data is li开发者_Python百科ke:

[Methods]
[0]
[1]
[2]

So itis length is 4.

I wonder why?


My guess is that the server returned data with a trailing comma, for example:

[1, 2, 3, ]

In IE, this array will be interpreted as having a length 4, while in standard compliant browsers, it will have a length 3.


[Methods] is a separate node shown by the debugger to separate functions from other values.
It does not actually exist in the object.

If an array has three items named 0, 1, and 2, its length will be 3.

0

精彩评论

暂无评论...
验证码 换一张
取 消