【发布时间】:2014-03-25 01:00:20
【问题描述】:
我无法理解为什么在下面的示例中,customclass 列表(response.results 和 results)充满了 LinkedHashMap。我希望在解析 JSON 输入流之后,列表中充满了自定义类,它们的类成员包含直接来自 JSON 的数据。相反,列表返回包含 LinkedHashMaps,即使它们是 Customclass 类型。
谁能解释一下?
Gson gson = new Gson();
Reader reader = new InputStreamReader(inputStream);
PlacesList response = gson.fromJson(reader, PlacesList.class);
List<Place> results = response.results;
使用的自定义类:
public class PlacesList implements Serializable {
@Key
public String status;
@Key
public String error_message;
@Key
public List<Place> results;
}
&
public class Place implements Serializable {
@Key
public String id;
@Key
public String name;
@Key
public String reference;
@Key
public String icon;
@Key
public String vicinity;
@Key
public Geometry geometry;
@Key
public String formatted_address;
@Key
public String formatted_phone_number;
@Override
public String toString() {
return name + " - " + id + " - " + reference;
}
public static class Geometry implements Serializable
{
@Key
public Location location;
}
public static class Location implements Serializable
{
@Key
public double lat;
@Key
public double lng;
}
}
【问题讨论】:
标签: java json list linkedhashmap