-4

I dont why it isnt working

var data = {
"vehicle": {
["id", "name", "description", "ip_address"], "records": [
["1", "lamborghini1", "gsdgsdgsdgsd", "112.206.114.21"],
["2", "honda civic", "murahun na kotse", "194.153.205.26"],
["3", "toyata", "gsdhgkhsdkjghsdgsdgs", "198.153.205.28"]
]
}
}]
}
});
});


var output = "<ul>";
for (var i in data.records) {
  output += "<li>" + data.records[i].name + "</li>";
}
output += "</ul>";

document.getElementById("placeholder").innerHTML = output;
Wesley Smith
  • 19,401
  • 22
  • 85
  • 133
  • 3
    "I dont why it isnt working" is not a valid question. See http://stackoverflow.com/help/how-to-ask, That said, you appear to have several syntax errors in your code – Wesley Smith Jan 22 '16 at 01:31
  • Your JSON is very wrong. The structure is not correct in several places but even if you fix that `data.records[i].name` wouldnt work because `records` is an array of *arrays* not objects, none of those *arrays* have a property named `name`. You'll just get `undefined` for each iteration. See http://jsfiddle.net/DelightedDoD/afs4u0vh/1/ , you need to rethink the structure of your data – Wesley Smith Jan 22 '16 at 01:45

1 Answers1

-1

Your JSON format is incorrect. Adjust it with this format

Adjust your code like this

{ "dataOne":[{"keyOne":"valueOne", "keyTwo":"valueTwo"},{"keyOne":"valueOne", "keyTwo":"valueTwo"},], "dataTwo":[{"keyOne":"valueOne"},{"keyOne":"valueOne"}] }