0
어쩌면 내가 비슷한 질문이 끝났지 만이 질문에 적절한 키워드를 얻을 수 없으므로 나와 함께하시기 바랍니다.아약스 응답에 json 개체의 액세스 목록
:
내가
List<String> listOne = some data list from the database
List<String> listTwo = another data list from the database
내가 생각 그래서 클라이언트로 JSON 객체로이 두List
를 보내 먼저 할 수 있습니다 자바 클래스에서 이러한 종류의 데이터를 가지고하는 것은 이것이다 어느
Map<String, List<String>> map = new HashMap<String, List<String>>();
map.put(listOne);
map.put(listTwo);
return new Gson().toJson(map);
또는
List<List<String>> list = new ArrayList<List<String>>();
list.add(listOne);
list.add(listTwo);
return new Gjson().toJson(map);
어떤 것이 더 좋은지 잘 모릅니다. 내가하고 싶은 다음 일은 클라이언트 측
$.post('some url', someData : 'that requires to know which data will be fetched',
function(data) {
// here how can I access the two list inside the list
// or the list inside the map
// i want to have a full control to the data
// example:
// Iterate the listOne on this $('#someId').append(listOne);
// Iterate the listTwo on this $('#anotherId').append(listTwo);
}, json);
적절하게이 작업을 수행 할 수있는 방법은 무엇입니까이 액세스입니까? 내 질문에 대한 의견이 분분하다면 이에 대한 답변을 드리겠습니다. 그런 다음 data.listOne
및 data.listTwo
직접 데이터에 액세스 할 수 있습니다
$.getJSON('some url', function(data) {
//Do something with data
});
: 당신이 $.GetJSON()
기능을 사용한다, 둘째
Map<String, List<String>> map = new HashMap<String, List<String>>();
map.put("listOne", listOne);
map.put("listTwo", listTwo);
return new Gson().toJson(map);
: