1

Possible Duplicate:
How to parse JSON in JavaScript

I get a string like this

 [["1","Pagamento de Placa","N","N"], ["2,""Contrato","N","N"], ["3","Ajuste de preço","N","N"],["4", "Abertura de cliente","N","N"], ["9","Outros","N","S"]]

I try

 var arr = new Array([["1","Pagamento de Placa","N","N"], ["2,""Contrato","N","N"], ["3","Ajuste de preço","N","N"],["4", "Abertura de cliente","N","N"], ["9","Outros","N","S"]]);

but not work

I want to turn into a real array, any idea how to do?

Thanks

3
  • You mean, the whole line is a string? Commented Feb 4, 2013 at 13:59
  • JSON.parse() should do that for you. Commented Feb 4, 2013 at 13:59
  • yes, the line is string Commented Feb 5, 2013 at 14:59

1 Answer 1

6

Use JSON.parse:

var arrayString = '[["1","Pagamento de Placa","N","N"], ["2,"Contrato","N","N"], ["3","Ajuste de preço","N","N"],["4", "Abertura de cliente","N","N"], ["9","Outros","N","S"]]';
var array = JSON.parse(arrayString);

(There's a duplicate " in the original string - I removed it.)

If you need to support older browsers use a library like json2.js or jQuery.parseJSON.

1
  • The first element of the second element of the parent array is missing a quote or has one too many. Commented Feb 4, 2013 at 14:03

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.