开发者

Prototypejs .evalJSON not returning object

开发者 https://www.devze.com 2022-12-26 06:27 出处:网络
I have this JSON (which validates according to JSONLint): [ { "BugCount":"2", "BugTitle":"C:\\\\INETPUB\\\\WWWROOT\\\\CLUBREADY2\\\\TRAINERS\\\\../Connections/LTC.as

I have this JSON (which validates according to JSONLint):

[
{
    "BugCount":"2",
    "BugTitle":"C:\\INETPUB\\WWWROOT\\CLUBREADY2\\TRAINERS\\../Connections/LTC.asp",
    "ErrLine":"141",
    "BugID":"702"
},
{
    "BugCount":"1",
    "BugTitle":"/admin/ajax_logagreementsig.asp",
    "ErrLine":"0",
    "BugID":"1322"
},
]

However, when I run data = json.e开发者_运维问答valJSON on it I get some problems. If I run .evalJSON(true) (to sanitize) an error happens within prototype saying "json" is undefined. The same happens if I do .evalJSON().

If I do .evalJSON with no parenthesis, then data is just an empty object and no error happens.

Is there something wrong with my JSON?


That's just a javascript object, you don't have to evaluate anything to get that working.

var data = [
 {
    "BugCount":"2",
    "BugTitle":"C:\\INETPUB\\WWWROOT\\CLUBREADY2\\TRAINERS\\../Connections/LTC.asp",
    "ErrLine":"141",
    "BugID":"702"
 },
 {
    "BugCount":"1",
    "BugTitle":"/admin/ajax_logagreementsig.asp",
    "ErrLine":"0",
    "BugID":"1322"
 }
];

The above will be just fine, and your data var will resolve to an array of two items. Note that I removed the trailing comma in that list, as it would cause a third, null-valued item in IE, but not in most other browsers.


I discovered my issue and it was a stupidity thing. I had accidentally left the default HTML on my .aspx page that is returning the JSON, so there was a whole "" built webpage inside the string I was trying to evaluate as JSON.

0

精彩评论

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

关注公众号