Alternatives to JavaScript eval() for parsing JSON

前端 未结 9 1306
忘了有多久
忘了有多久 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 08:47

    Using JavaScript’s eval is unsafe. Because JSON is just a subset of JavaScript but JavaScript’s eval allows any valid JavaScript.

    Use a real JSON parser like the JSON parser from json.org instead.

提交回复
热议问题