开发者

Best way to convert JSON data to an object in JavaScript?

I am currently using eval i开发者_开发技巧n JavaScript to convert JSON data returned from the server into an object.

eval ("myObject="+data);

I've been told that eval is 'evil' and can open up big security problems.

I'm wondering - is using eval to convert JSON data to an object the accepted practice? Or is there a better way?


The reason eval is considered a bad practice is that user can evaluate anything that is sent from the server. This means if you have comments forum and the user submits some JavaScript code for the comments and you eval on the client side then your website can easily be hijacked.

I like the JQuery-Json plug-in. You can check it out using the following link:

link text

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜