배열로서 웹 서비스의 결과를 얻고 결과를 반복하여 모든 데이터를 가져 오려고합니다. 내가 지금까지했던 : 나는 결과를 반환 할 때 내가 결과로 배열을 가져 오지 못했습니다 (AJAX-JSON에 의해 webservice 호출)
return json_encode($newFiles);
를 사용하여 내 웹 서비스에서
그 결과는 다음과 같습니다 :
"[{\"path\":\"c:\\\\my_images\\\\123.jpg\",\"ID\":\"123\",\"FName\":\"John\",\"LName\":\"Brown\",\"dept\":\"Hr\"}]"
다음 내 웹 응용 프로그램에서 내가 RestService 클래스의 다음 코드로 나머지 웹 서비스를 호출하십시오.
public function getNewImages($time) {
$url = $this->rest_url['MyService'] . "?action=getAllNewPhotos&accessKey=" . $this->rest_key['MyService'] . "&lastcheck=" . $time;
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);
if ($data) {
return json_decode($data);
} else {
return null;
}
}
내 제어 도구
public function getNewImgs($time="2011-11-03 14:35:08") {
$newImgs = $this->restservice->getNewImages($time);
echo json_encode$newImgs;
}
and I'm calling this `enter code here`controller method by AJAX:
$("#searchNewImgManually").click(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
async: true,
datatype: "json",
url: "<?PHP echo base_url("myProjectController/getNewImgs"); ?>",
success: function(imgsResults) {
alert(imgsResults[0]);
}
});
});
대신 나에게 그냥 나에게 따옴표 (결과의 첫 번째 charachter)를주고 첫 번째 개체를주는 "
왜 즉 : R 나는 다음과 같은 코드가? JSON 형식으로 전달하고 AJAX에서 데이터 유형을 "JSON"으로 언급했습니다.
더 자세한 설명이 필요하면 알려주세요. 고마워요 :)