我解析通过GSON JSON字符串,这是JSON字符串JSON解析与GSON返回null对象
[
{
"ID": 1,
"Name": "Australia",
"Active": true
},
{
"ID": 3,
"Name": "Kiev",
"Active": true
},
{
"ID": 4,
"Name": "South Africa",
"Active": true
},
{
"ID": 5,
"Name": "Stockholm",
"Active": true
},
{
"ID": 6,
"Name": "Paris",
"Active": true
},
{
"ID": 7,
"Name": "Moscow",
"Active": true
},
{
"ID": 8,
"Name": "New York City",
"Active": true
},
{
"ID": 9,
"Name": "Germany",
"Active": true
},
{
"ID": 10,
"Name": "Copenhagen",
"Active": true
},
{
"ID": 11,
"Name": "Amsterdam",
"Active": true
}
]
,这是将要useed
public class MyBranch extends Entity {
public MyBranch() {
super();
}
public MyBranch (int id, String name, String isActive) {
super();
_ID = id;
_Name = name;
_Active = isActive;
}
@Column(name = "id", primaryKey = true)
public int _ID;
public String _Name;
public String _Active;
}
Gson gson = new Gson();
Type t = new TypeToken<List<MyBranch >>() {}.getType();
List<MyBranch > list = (List<MyBranch >) gson.fromJson(json, t);
的对象列表构造,它有10个对象,但问题是对象的所有数据成员都是null,我不知道这是什么问题。该实体是OrmDroid的实体类。
它不与ArratList工作压力太大。 – Areff 2013-03-08 10:55:05
是的......问题是你不使用'@ SerializedName',并且变量名称与JSON标签不同,请参阅@vmironov post。 – madlymad 2013-03-08 10:57:30