Alternatives to JavaScript eval() for parsing JSON

前端 未结 9 1289
忘了有多久
忘了有多久 2020-12-01 08:23

Quick Question. Eval in JavaScript is unsafe is it not? I have a JSON object as a string and I need to turn it into an actual object so I can obtain the data:



        
9条回答
  •  一生所求
    2020-12-01 08:58

    Another great alternative is YUI: http://yuilibrary.com/yui/docs/json/

    So your code would be something like:

    Y.JSON.parse('{"id": 15, "name": "something"}');
    

提交回复
热议问题