Parse Json Object In Javascript Getting Undefined
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,
Solution 1:
var obj = JSON.parse(response);
You can see it explained here.
Here you can check if it is supported in your target browser.
Solution 2:
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.
Solution 3:
try something like this
vardata = [
["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
vardata = '[["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]);
}
}
Post a Comment for "Parse Json Object In Javascript Getting Undefined"