json 개체 배열을 보낼 때 jquery ajax 메서드를 사용하면 내용을 구문 분석하고 jquery의 listview에서 데이터를 표시 할 수 있지만 하나의 단일 개체 만 있으면 동일한 jQuery 아약스 메서드는 데이터를 구문 분석 할 수 없습니다. 여기Jquery Ajax 메서드는 여러 json 개체와 함께 작동하지만 단일 json 개체가 아닌
내 JSON 객체 배열 : 여기
{"menuService":[{"idmenu":"0","itemCatagory":"Main Course","itemDescription":"Food from UP","itemImagePath":"http://localhost:8080/fotservice/ItemImage?id=Steam Rice","itemName":"Steam Rice","rate":"100.5","subItemName":"Half Plate Steam Rice","subItemNameRate":"100.5"},{"idmenu":"5","itemCatagory":"Main Course","itemDescription":"tasty lunch","itemImagePath":"http://localhost:8080/fotservice/ItemImage?id=Lunch Combo(raita,rice,dal,salad)","itemName":"Lunch Combo(raita,rice,dal,salad)","rate":"123.0","subItemName":"lunch(dal,rice)","subItemNameRate":"100.5"}]}
내 단일 JSON 개체 : 나는 JQuery와해서 getJSON 시도
$.ajax({
url: "http://localhost:8080/fotservice/rest/menu/"+cat+"/items",
type: 'GET',
dataType: 'json',
contentType: "application/json; charset=utf-8",
success: function(response) {
var markup = "";
$.each(response.menuService, function(index, result) {
var $template = $('<div><li> <a data-transition="slide" href="desc.html?cat='+result.itemName+'" rel="external" > <img class="profile"> <p class="from"> </p><p class="tweet"> </p></li></a></div>');
$template.find(".profile").attr("src", result.itemImagePath);
$template.find(".from").append(result.itemDescription);
markup += $template.html();
});
$("#tweet-list").append(markup).listview("refresh", true); // The true parameter indicates we want to refresh the entire list, not just the list items.
},
timeout: 6000, // Timeout after 6 seconds
error: function(jqXHR, textStatus, errorThrown) {
console.log("Error, textStatus: " + textStatus + " errorThrown: "+ errorThrown);
$.mobile.hidePageLoadingMsg();
//show error message
$("<div class='ui-loader ui-overlay-shadow ui-body-e ui-corner-all'><h1>"+ $.mobile.pageLoadErrorMessage +"</h1></div>")
.css({ "display": "block", "opacity": 0.96, "top": 100 })
.appendTo($.mobile.pageContainer)
.delay(800)
.fadeOut(1000, function() {
$(this).remove();
});
}
});
: 여기
{"menuService":{"idmenu":"2","itemCatagory":"xyz","itemDescription":"fghjkl;","itemImagePath":"http://localhost:8080/fotservice/ItemImage?id=Dal makhni","itemName":"Dal makhni","rate":"121.5","subItemName":"Half plate Dal makhni","subItemNameRate":"121.56"}}
및 내 JQuery와 아약스 방법 그 방법은 또한 같은 행동을하고있다.
$ .each는 객체 목록을 처리 할 수 없습니다 ('[{...}, {...}]). ')는 후자의 경우 키를 반복하기 때문에 객체 ('{...} ')를 처리하는 것과 같은 방식입니다. 하나의 개체 목록을 보낼 수 있습니까? – Brian