我想反序列化我的对象,但我不能得到任何错误!Json反序列化错误
我在android上使用gson来读取json文件。
,这是我的请求类,我利用休息服务器我反序列化。
public Object getListaSeguradoras(String _codPais, String _tipoPesquisa)
{
try {
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(Config.WS_PATH);
post.setHeader("content-type", "application/json; charset=UTF-8");
post.addHeader("Client-Application","xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
//Make object in JSON format
JSONObject dato = new JSONObject();
dato.put("CodPais", _codPais);
dato.put("TipoPesquisa", _tipoPesquisa);
StringEntity entity = new StringEntity(dato.toString());
post.setEntity(entity);
HttpResponse resp = httpClient.execute(post);
String respStr = EntityUtils.toString(resp.getEntity());
Gson gson = new Gson();
Type collectionType = new TypeToken<Collection<SeguradoraLista>>(){}.getType();
Collection<SeguradoraLista> ListaSeguradoras = gson.fromJson(respStr, collectionType);
return ListaSeguradoras;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
我的目标:
这是我的getter和setter
public class SeguradoraLista{
public String SeguradoraId;
public String Nome;
public String getSeguradoraId() {
return this.SeguradoraId;
}
public String getNome() {
return this.Nome;
}
public void setSeguradoraId (String SeguradoraId) {
this.SeguradoraId = SeguradoraId;
}
public void setNome (String Nome) {
this.Nome = Nome;
}
}
我的JSON:
这是对我的字符串JSON字符串respStr
[{"SeguradoraId":"19","Nome":"AIG Europe"},
{"SeguradoraId":"25","Nome":"AIOI Insurance Co. Of Europe"},
{"SeguradoraId":"28","Nome":"Aktiv Forsikring A/S"},
{"SeguradoraId":"160","Nome":"Enter Forsikring AS"},
{"SeguradoraId":"167","Nome":"Euro Insurances Ltd."},
{"SeguradoraId":"189","Nome":"Försäkrings-AB Volvia"},
{"SeguradoraId":"219","Nome":"Gjensidige NOR Forsikring"},
{"SeguradoraId":"245","Nome":"If Skadeforsikring NUF"},
{"SeguradoraId":"265","Nome":"Jernbanepersonalets Forsikring Gjensiding"},
{"SeguradoraId":"271","Nome":"KLP Skadeforsikring AS"},
{"SeguradoraId":"284","Nome":"Landbruksforsikring"},
{"SeguradoraId":"309","Nome":"Lloyd's v/Vital Skade AS"},
{"SeguradoraId":"459","Nome":"SpareBank 1 Skadeforsikring AS"},
{"SeguradoraId":"472","Nome":"Tennant Forsikring nuf"},
{"SeguradoraId":"473","Nome":"Terra Skadeforsikring AS"},
{"SeguradoraId":"494","Nome":"Trygg-Hansa Forsikring Nuf"},
{"SeguradoraId":"517","Nome":"Vesta Skadeforsikring A/S"},
{"SeguradoraId":"536","Nome":"Zürich Forsikring"}]
我做错了什么?我不能使这个直接去实现?
什么是'SeguradoraLista'? –
对不起,是我的对象,我修复了我的帖子。 – kaub0st3r