는 내가 JSON 결과에 넣어 객체의 목록을 작성 : JSON에서 복잡한 객체의 목록을 반복 하시겠습니까?
Person personA = new Person("nameA", "age");
Person personB = new Person("nameB", "age");
Person personC = new Person("nameC", "age");
List<Car> cars = new ArrayList<Car>();
cars.add(new Car("Blue", "Small", personA));
cars.add(new Car("Green", "Big", personB));
cars.add(new Car("Red", "Big", personC));
내 JSON 결과지도에서
, 내가 넣어 :result.put("cars", cars);
어떻게 자바 스크립트에서이 컬렉션을 반복 할 수 있습니다. 나는 객체의 "깊은"요소에 접근 할 필요가있다.
$.getJSON(window.actionName,{
someId: someId}, function (ans){
//I want something like this
foreach(car in ans.cars){
car.person.age
}
});
편집 :
result map private Map<String,List<Car>> result =
new HashMap<String, List<Car>>();
result.put("cars", cars);
하지만이 목록은 클라이언트로 전송되지 않습니다 seemes. 나는 크롬 디버거에서이 오류를 얻을 :
ReferenceError: value is not defined
... failed to load resource: the server responded with a status of 500 (Internal Server Error)
답변 : 제가 주석을 hibernante했다 객체를 직렬화 때문에 오류가 있었다. 나는 콩이 그 개체를 생성하고이를 직렬화 지금 직렬화 (및 반복이 작동은)
있다. 자바 스크립트와 아무 관련이 없습니다. 셸/IDE/터미널 출력에서 JAVA 오류를 확인하십시오. –
예, 그것은 prbolem이지도의 직렬화에있는 것처럼 보입니다. 그것은 Map>을 직렬화 할 수는 없지만 Map 를 직렬화 할 수 있습니다. –
vale4674