开发者

JQuery Eval for null JSon object

开发者 https://www.devze.com 2023-03-15 14:41 出处:网络
I am using Jquery\'s $.ajax() method to retrieve a JSON object from a Webservice. If my data (JSON) is null or undefined, I am getting a

I am using Jquery's $.ajax() method to retrieve a JSON object from a Webservice. If my data (JSON) is null or undefined, I am getting a

Microsoft JScript compilation error :
Expected ']'

error for the below line of code:

var data1 = eval("(" + msg + ")");

This works fine in VS2005 and VS2008 is this a setting in VS2010? or am I doing a开发者_运维知识库nything wrong


Not sure what this has to do with visual studio...

If you're including jQuery you might very well do

var data1 = $.parseJSON(msg);

Instead of using eval. If that still fires an error, the server response might be malformed, can you please paste it here?

Cheers!

0

精彩评论

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