2024-11-30 09:16:10
建一个类:
public class Resp {
private String code;
private Result result;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public Result getResult() {
return result;
}
public void setResult(Result result) {
this.result = result;
}
public static class Result{
private String corpid;
public String getCorpid() {
return corpid;
}
public void setCorpid(String corpid) {
this.corpid = corpid;
}
}
}
然后:
String json="{\"code\":\"00\",\"result\":{\"corpid\":\"456\"}}";
Gson gson=new Gson();
Resp resp= gson.fromJson(json,Resp.class);
resp.getCode();//code
resp.getResult().getCorpid();//corpid