私はphpスクリプトから次のデータを取得しています..
{"errorno":"fe_200","message":"successful","univ":[{"univ_id":"1","univ_name":"abc","slug":"uptu","thumb":"http:\/\/www.fs.com\/notes\/img\/uptu.gif","table_prefix":"uptu"},{"univ_id":"2","univ_name":"def","slug":"gtu","thumb":"http:\/\/www.fs.com\/notes\/img\/gtu.gif","table_prefix":"gtu"},
{"univ_id":"3","univ_name":"jvc university","slug":"jntu","thumb":"http:\/\/www.fs.com\/notes\/img\/jntu.gif","table_prefix":"jntu"}
}]}
GSONを使用してこれを解析したい。
私は次のクラスを書いています:
class WebsiteResults {
public WebsiteResults() {}
private String errorno;
private String message;
private List<univ> results;
// other attributes
public String getErrorNo() {
return errorno;
}
public String getMessage() {
return message;
}
public List<univ> getResults() { return results; }
public void setErrorNo(String errorno) {
this.errorno = errorno;
}
public void setMessage(String message) {
this.message = message;
}
public void setResults(List<univ> results) { this.results = results; }
public String toString() { return "Results[" + results + "]";}
static class univ {
private String univ_id;
private String univ_name;
public String getUnivID() { return univ_id; }
public String getUnivName() { return univ_name; }
public void setUnivID(String univ_id) { this.univ_id = univ_id; }
public void setUnivName(String univ_name) { this.univ_name = univ_name; }
public String toString() { return "Result[id:" + univ_id +",title:" + univ_name + "]"; }
}
}
univ_id と univ_name の配列を取得したいです。
しかし、結果= nullを取得しています。誰かが私が間違ったことを説明するのを助けることができます.
WebsiteResults results = new Gson().fromJson(reader, WebsiteResults.class);
String errno = results.getErrorNo();
String result = results.toString();