Convert JSON string to array of JSON objects in Javascript

前端 未结 6 1681
感情败类
感情败类 2020-11-27 12:14

I would like to convert this string

{\"id\":1,\"name\":\"Test1\"},{\"id\":2,\"name\":\"Test2\"}

to array of 2 JSON objects. How should I do

6条回答
  •  爱一瞬间的悲伤
    2020-11-27 12:47

    I know a lot of people are saying use eval. the eval() js function will call the compiler, and that can offer a series of security risks. It is best to avoid its usage where possible. The parse function offers a more secure alternative.

提交回复
热议问题