0

I have a question. Maybe someone have an idea. I want to convert a string array with JSON Objects into an array. Like this:

var test = "[{'test1':1,'test2':2},{'test1':1,'test2':2}]";

to:

var test1 = [{'test1':1,'test2':2},{'test1':1,'test2':2}];

my code:

var test = "[{'test1':1,'test2':2},{'test1':1,'test2':2}]";
var array = [];
var array = JSON.parse("[" + test + "]");

But this code don't work.

Do you have any idea?

Thanks for all.

3
  • 1
    That's not JSON syntax. JSON.parse expects valid JSON. Commented Oct 21, 2021 at 16:29
  • How can I solve the problem? Commented Oct 21, 2021 at 16:36
  • Research what JSON syntax rules are. The duplicate references at the top have the info you need. To be specific: keys and string values need to use double quote delimiters, not single quotes. Commented Oct 21, 2021 at 16:37

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.