0
json으로 구문 분석이JSON - 잭슨 배열처럼
{
"resultCode": "0000",
"resultMsg": "",
"pageCount": "6",
"curPage": "1",
"infoItems": [
{
"sID": "268",
"location": "222",
"unit": "",
"time": "2012-11-02 17:51:46",
"longitude": "111",
"latitude": "222",
"reason": "some",
"dealContent": ""
},
{
"sID": "267",
"location": "fgg",
"unit": "yyg",
"time": "2012-11-02 17:49:14",
"longitude": "111",
"latitude": "222",
"reason": "some",
"dealContent": ""
}
]
}
이 어떻게 자바 클래스로 디코딩 할 수 ?
내가
public class UploadedInfoObjEx {
public String resultCode;
public String resultMsg;
public String pageCount;
public String curPage;
public Items[] infoItems;
public class Items {
private String sID;
private String location;
private String unit;
private String longitude;
private String latitude;
private String reason;
private String time;
private String dealContent;
}
}
같은 클래스를 작성하고 JSON 읽을
ObjectMapper mapper = new ObjectMapper();
UploadedInfoObjEx uploadedInfoObjEx = mapper.readValue(jsonString, UploadedInfoObjEx.class);
오류 자료 [에서
org.codehaus.jackson.map.JsonMappingException: No suitable constructor found for type [simple type, class com.rayboot.wl.object.UploadedInfoObjEx$Items]: can not instantiate from JSON object (need to add/enable type information?)
입니다 : [email protected]; 줄 : 1, 열 : 81] (참조 체인을 통해 : com.rayboot.wl.object.UploadedInfoObjEx [ "infoItems"])
누구든지 나를 도울 수 있습니까? 감사합니다.
공개 설정하십시오. '@JsonProperty' 주석을 추가하십시오; 비공개 필드를 "볼"수 있도록 기본 인트로 스펙 가시성을 변경하십시오. 이것을 달성하는 많은 방법. – StaxMan