I'm doing Android PhoneGap project in my company. I have a JSON file and want to get it into my HTML select box. As I am still newbie, I haven't understand about JSON parsing mostly.
Here's my JSON File (city.json) :
[{"CityID":1,"CityName":"Magelang"},{"CityID":2,"CityName":"Jayapura"},{"CityID":3,"CityName":"Aceh"}]
I really didn't know whether it's needed to parsed or not. I have followed RaYell answer in this thread. Jquery getJSON populate select menu question
So, I code these to populate the result into the option in select box.
$.getJSON('city.json', function(data){
var html = '';
var len = data.length;
for (var i = 0; i< len; i++) {
html += '<option value="' + data[i].CityID + '">' + data[i].CityName + '</option>';
}
$('#city').append(html);
});
But it didn't worked on my code. My select box has none options :( Any solutions? Thanks before.