以下代码不起作用。无法将 JSON 转换为 JAVA 对象。如何解决?谢谢。
import com.google.gson.Gson;
public class Rest{
public static void main(String[] args) {
String json = "{'CBE_GetNewSessionResponse': {'CBE_GetNewSessionResult': '10016-300-0000022151'}}";
Gson gson = new Gson();
Data data = gson.fromJson(json, Data.class);
System.out.println(data.getResponse());
}
}
class Data {
private CBE_GetNewSessionResponse response;
public CBE_GetNewSessionResponse getResponse() {
return response;
}
public void setResponse(CBE_GetNewSessionResponse response) {
this.response = response;
}
class CBE_GetNewSessionResponse{
private String CBE_GetNewSessionResult;
public String getCBE_GetNewSessionResult() {
return CBE_GetNewSessionResult;
}
public void setCBE_GetNewSessionResult(String cBE_GetNewSessionResult) {
CBE_GetNewSessionResult = cBE_GetNewSessionResult;
}
}
}