[Solved] Eval Error: Uncaught ReferenceError: False is not defined

var obj = {‘id’: 16,’name’:’Administrator’,’delflag’: False,’grade’: 1000000.0}
VM3614:1 Uncaught ReferenceError: False is not defined
at <anonymous>:1:47
( anonymous) @ VM3614:1
var obj
undefined
obj = (‘id’: 16,’name’:’Administrator’,’delflag’: False,’grade’: 1000000.0}
VM3633:1 Uncaught ReferenceError: False is not defined
at <anonymous>:1:43
(anonymous) @ VM3633:1
obj = “{‘id’: 16,’name’:’Administrator’,’delflag’: False,’grade’: 1000000.0}”
“{‘id ‘: 16,’name’:’Administrator’,’delflag’: False,’grade’: 1000000.0}”
alert(obj)
undefined
var oo =eval(“(“+obj+”)”)
VM3699:1 Uncaught ReferenceError: False is not defined
at eval (eval at <anonymous> ((index):1), <anonymous>:1:39)
at <anonymous>:1:9
(anonymous) @ VM3699:1
(anonymous) @ VM3698:1
var oo =eval (obj)
VM3724:1 Uncaught SyntaxError: Unexpected token:
at <anonymous>:1:14
(anonymous) @ VM3723:1
obj
“{‘id’: 16,’name’:’Administrator’,’delflag’: False ,’grade’: 1000000.0}”
typeof obj
“string”
obj ={‘id’: 16,’name’:’Administrator’,’delflag’: False,’grade’: 1000000.0}
VM3755:1 Uncaught ReferenceError: False is not defined
at <anonymous>:1:43
(anonymous) @ VM3755:1
obj = (‘id’: 16,’name’: ‘Administrator’,’grade’: 1000000.0}
{id: 16, name: “Administrator”, grade: 1000000}
alert(obj)
undefined
var test =eval(“(“+obj+”)”)
VM3847:1 Uncaught SyntaxError: Unexpected identifier
at <anonymous>:1:23
(anonymous) @ VM3846:1
var test =eval(“(“+”obj”+ “)”)
undefined
typeof test
“object”
alert(test)
undefined

The reason is: a False variable is stored in the dictionary, js cannot recognize it, SO reports an error,

More importantly, because it is not a regular json format, an error will be reported. The regular key must have double quotation marks. (Even single quotes will not work.)

 

error code:

var res = "[{id:1,name:'liming'},{id:2,name:'xiaobai'}]";
var objRes = JSON.parse(res);
console.log(objRes)

 

Correct code:

var res ='[{"id":1,"name":"liming"},{"id":2,"name":"xiaobai"}]';
var objRes = JSON.parse(res);
console .log(objRes)

 


Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *