我不确定您的代码是什么样的,但@SerializedName("-item")
对我来说似乎工作正常
class Data {
private List<ItemData> ItemData = new ArrayList<ItemData>();
@Override
public String toString() {
return "Data [ItemData=" + ItemData + "]";
}
}
class ItemData {
@SerializedName("-item")
private String _item;
private String id;
private String name;
private String description;
private String category;
@Override
public String toString() {
return "ItemData [_item=" + _item + ", id=" + id + ", name=" + name
+ ", description=" + description + ", category=" + category
+ "]";
}
}
用法
Gson gson = new Gson();
String jsonString = "{\r\n" + " \"ItemData\" : [{\r\n"
+ " \"-item\" : \"A\",\r\n" + " \"id\" : \"100\",\r\n"
+ " \"name\" : \"abc\",\r\n"
+ " \"description\" : \"abcd\",\r\n"
+ " \"category\" : \"xyz\"\r\n" + " }\r\n" + " ]\r\n"
+ "}\r\n";
Data item = gson.fromJson(jsonString, Data.class);
System.out.println(item);
输出
Data [ItemData=[ItemData [_item=A, id=100, name=abc, description=abcd, category=xyz]]]
^^^^^^^