jquery - Converting JSON not returning Javascript array -
i have json returning server looks this
[{"name1":"value1","name2":"value2"},{"name1":"value1","name2":"value2"},{"name1":"value1","name2":"value2"}]
i handle using
var data = json.parse(json);
then, once doing this, call in loop
data.item(i);
or using function data.splice(i, 1); giving me error
data.item not function
or
data.splice not function
i'm pretty because not true javascript array, haven't found has told me how convert one
edit looking .item() function used in nodelist (from things getelementbyclassname) however, not solve issue .splice
your json invalid - needs commas separating objects:
[{"name1":"value1","name2":"value2"},{"name1":"value1","name2":"value2"},{"name1":"value1","name2":"value2"}]
parse json were:
var data = json.parse(json);
and access each object, use index of array:
var element1 = data[0]; // first element var element2 = data[1]; // second element
etc.
and access values in objects:
var name1 = data[0].name1; // value1
or even, since you've defined element1
variable:
var name1 = element1.name1;
if you're using loop:
for (var = 0, l = arr.length; < l; i++) { console.log(data[i]); }
Comments
Post a Comment