Web サービスの結果を配列として取得し、その結果をループしてすべてのデータを取得しようとしています。私がこれまでに行ったこと:
使用する結果を返すときに Web サービスで
return json_encode($newFiles);
結果は次のとおりです。
"[{\"path\":\"c:\\\\my_images\\\\123.jpg\",\"ID\":\"123\",\"FName\":\"John\",\"LName\":\"Brown\",\"dept\":\"Hr\"}]"
次に、私の Web アプリケーションでは、RestService クラスの次のコードで残りの Web サービスを呼び出しています。
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]);
}
});
});
しかし、最初のオブジェクトを与える代わりに、引用符 (結果の最初の文字) を与えるだけです」
何故ですか?私はJSON形式で渡しています.AJAXではデータ型を「JSON」と言いました!
さらに説明が必要な場合はお知らせください。ありがとう :)