我有一個類,我只需要一個方法..所以我已經在方法中聲明它。在定義爲方法的類中使用Gson返回null
現在,當我嘗試從這個類轉換爲json使用gson我得到空。
我的代碼是這樣的:
private Response performGetClientDetails(HashMap<String, Object> requestMap) {
class ClientDetails {
String id;
String name;
String lastName;
int accoundId;
public ClientDetails(String id, String name, String lastName, int accoundId) {
this.id = id;
this.name = name;
this.lastName = lastName;
this.accoundId = accoundId;
}
}
ClientDetails clientDetails = new ClientDetails(client.getId(), client.getFirstName(), client.getLastName(), client.getAccount().getId());
Gson gson = new Gson();
return new Response(true, gson.toJson(clientDetails));
}
什麼返回null
是這樣的:gson.toJson(clientDetails)
..其應該返回一個JSON字符串。
什麼是空? 'performGetClientDetails'返回? 「Response」類所做的一些事情? Response的構造函數對第二個參數做了什麼? – 2013-04-23 20:45:13
@mattb我編輯了帖子..請看看,謝謝。 – Hasan 2013-04-23 20:46:50
@mattb幫助請.. – Hasan 2013-04-23 20:58:56