开发者

JSLINT Error MSG with JSON.parse()

using JSLINT on this simple example of receiving JSON via Assignment(without eval()), although simple, I'm concered with doing this correctly before tackling larger task:

http://www.hunlock.com/blogs/Mastering_JSON_%28_JavaScript_Object_Notation_%29#quickIDX6

var JSONFile = "someVar = {\"color\":\"blue\"}";

var myParse = JSON.parse(JSONFile);
alert(JSONFile);

The error returned is:

开发者_JAVA技巧
Error:
Problem at line 5 character 1: 'alert' was used before it was defined.   
alert(JSONFile);

Tried on: 08/25/11

var JSONFile = "someVar = {\"color\":\"blue\"}";

var myParse = JSON.parse(JSONFile);
/*global alert */alert(JSONFile);

Returned From Scratchpad:

[06:27:25.349] JSON.parse: unexpected character @Scratchpad:4 @ Scratchpad:4


This seems like it has pretty good explanation: http://www.jslint.com/lint.html

I am reading through it now since I am new to javascript (and therefore jslint as well), and I am finding it useful.

This is what I found on some other site that seemed to work for me: Prefix your alert with /*global alert */ That should work. I think this has something to do with alert having some special meaning in JSLINT

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜