저는 JSON에 조금 익숙하여 이것을하기위한 최선의 방법을 이해하려고 노력하고 있습니다. postcode와 energyrating이라는 두 가지 변수가 JSON에 넣고 for 루프로 파싱하려고합니다.루프 동안이 올바른 JSON 구조는 무엇입니까?
하나의 변수에서 작동하도록 만들 수 있지만 두 개가 있으면 작동하지 않습니다.
function addNew(postcodes) {
if(postcodes.length > 0) {
for(var i = 0; i < postcodes.length; i++) {
var address = postcodes[i];
var rating = energyrating[i];
geocoder.geocode({ 'address': address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var image = '../img/markers/' + rating + '.png';
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
icon: image
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
} else {
alert("Sorry, no data was found.");
}
}
가 어떻게이 두 변수와 함께 작동하도록받을 수 있나요 :
여기header('Content-type: application/json');
$postcodeArray = array('postcodes' => array("E6 2JG","SE1 2AQ","DA1 1DZ"), 'energyrating' => array("A","B","C","D","E","F","G"));
die(json_encode($postcodeArray));
내 jQuery를 수 있습니다 : 여기
내 JSON입니까?
'addNew()'함수는 어떻게 불려지나요? 또한 'postcodes'와 'energyrating'이라는 데이터가 다른 길이의 배열이므로 동일한 for 루프를 사용하여 두 배열을 모두 루프 할 수 있습니까? – nnnnnn