저는 작업등을 처음 사용합니다. http 어댑터에서 json 응답을 얻으려고했지만 장치에 표시 할 수 없습니다. 내 자바 스크립트 코드에 몇 가지 경고를 추가했으며 json 개체의 크기를`정의되지 않음 '으로 반환하는 것으로 나타났습니다.
다음은 내 어댑터 자바 스크립트 파일입니다.
function getGooglePlaces(location,name) {
var input = {
method : 'get',
returnedContentType : 'json',
path : 'maps/api/place/search/json',
headers: {
Host: 'maps.googleapis.com'
},
parameters : {
'key' : MyKey,
'location' : location,
'radius' : '10000',
'sensor' : 'false',
'name' : name
}
};
var response = WL.Server.invokeHttp(input);
return response;
}
function addGooglePlace(param1) {
var input = {
method : 'put',
returnedContentType : 'json',
path : 'userInputRequired'
};
return WL.Server.invokeHttp(input);
}
내 main.js 파일 :
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(loadHTTPRecords);
}
else{x.innerHTML="Geolocation is not supported by this browser.";}
}
function loadHTTPRecords(position){
var invocationData = {
adapter : 'GooglePlaces',
procedure : 'getGooglePlaces',
parameters : [position.coords.latitude+','+position.coords.longitude,'dead battery']
};
WL.Client.invokeProcedure(invocationData,{
onSuccess : loadHTTPQuerySuccess,
onFailure : loadHTTPQueryFailure
});
}
function loadHTTPQuerySuccess(result){
WL.Logger.debug("Retrieve success" + JSON.stringify(result));
displayFeeds(result);
}
function loadHTTPQueryFailure(result){
WL.Logger.error("Retrieve failure");
}
function displayFeeds(items){
alert("In displayFeeds");
// Get the size of an object
var ul = $('#itemsList');
alert("before for loop");
alert(items.size);
for (var i = 0; i < items.size; i++) {
alert("inside for loop 1");
for(var j=0;j<i;j++){
alert("in for loop 2");
var li = $('<li/>').html(items[i].name);
li.append($('<hr>'));
ul.append(li);
}
}
}
내가 뭘 잘못하고 있는지 알려주세요.
내 샘플 json 응답
{
"html_attributions": [
],
"isSuccessful": true,
"responseHeaders": {
"Alternate-Protocol": "443:quic",
"Cache-Control": "public, max-age=300",
"Content-Type": "application\/json; charset=UTF-8",
"Date": "Tue, 11 Feb 2014 12:04:13 GMT",
"Expires": "Tue, 11 Feb 2014 12:09:13 GMT",
"Server": "mafe",
"Transfer-Encoding": "chunked",
"Vary": "Accept-Language",
"X-Frame-Options": "SAMEORIGIN",
"X-XSS-Protection": "1; mode=block"
},
"responseTime": 236,
"results": [
{
"geometry": {
"location": {
"lat": 52.057049,
"lng": 1.153298
}
},
"icon": "http:\/\/maps.gstatic.com\/mapfiles\/place_api\/icons\/cafe-71.png",
"id": "ec0955fb06fd95d639c89d12475624627250abac",
"name": "Costa Coffee",
"opening_hours": {
"open_now": true
},
"price_level": 2,
"rating": 3.9,
"reference": "CnRuAAAABmdY6kIxRQZw68hqjZ_wwBE29sdSgYuOkXf2IvZTe77aG-AgoCaahu1c9cddHA0Z1D2EdELAEuDyl38xV1G5YcvP3pOm2p0IwVkuvYIJSA1IKAGLIQym21SpXvhUSqBxrpHKBvgTNnUg69lHROaMyxIQvvP8SeCG_dzKi_JgrdrgRRoUQXqH4UkDtA-58bCbdRzUCdXTRVU",
"types": [
"cafe",
"food",
"establishment"
],
"vicinity": "1-5 Queen St, Ipswich"
},
질문을 제대로 이해했다면 items.size를 통해 결과의 길이를 얻으려고합니다. 결과의 길이를 얻으려면 items.invocationResult.results.length
총 결과 수를 제공하는 항목 을 사용해야합니다 . 여기서 항목은 어댑터에서 오는 응답이고 invocationResult
결과 및 기타 매개 변수를 포함하며 여기에서 액세스를 위해 결과에 액세스해야합니다. 특정 출력 만.
질문을 제대로 이해하지 못한 경우 항목을 통해 얻으려는 항목을 정확히 알려주십시오.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다