-4

I got response in json format but i m facing problem to how to parse it below is my code

var jsonValue = JSON.stringify(response);

after alert jsonValue i got

[
    ["vlue1", 18, "ram", "xmy"],
    ["value2", 21, "abc", "xyz"]
]

How to parse it in JavaScript?

thefourtheye
  • 233,700
  • 52
  • 457
  • 497
Ravi Chothe
  • 180
  • 5
  • 17

3 Answers3

2
var obj = JSON.parse(response);

You can see it explained here.

Here you can check if it is supported in your target browser.

Raul Guiu
  • 2,374
  • 22
  • 37
0

stringify()

The JSON.stringify() method converts a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.

parse()

The JSON.parse() method parses a string as JSON, optionally transforming the value produced by parsing.

WhiteLine
  • 1,919
  • 2
  • 25
  • 53
0

try something like this

var data = [
    ["vlue1", 18, "ram", "xmy"],
    ["value2", 21, "abc", "xyz"]
];
for(var i = 0;i < data.length;i++){
    var tem_arr = data[i];
    for(var j = 0;j < tem_arr.length;j++){
        console.log(tem_arr[j]);
    }
}

JSON.stringify turns an object in to a JSON text and stores that JSON text in a string.

JSON.parse turns a string of JSON text into an object.

EDITED

var data = '[["vlue1", 18, "ram", "xmy"],["value2", 21, "abc", "xyz"]]';
data = JSON.parse(data)
for(var i = 0;i < data.length;i++){
    var tem_arr = data[i];
    for(var j = 0;j < tem_arr.length;j++){
        console.log(tem_arr[j]);
    }
}
rajesh kakawat
  • 10,826
  • 1
  • 21
  • 40