Java 无法使用Gson获取值

Java 无法使用Gson获取值,java,json,list,gson,Java,Json,List,Gson,我有一个列表对象。我正在传递给Gson的那个列表 Gson gson = new Gson(); String toJson = gson.toJson(userDetailFeedNotifierVoList); System.out.println("Gson Object : " + toJson); 我现在进入控制台: [ { "title": "Suman Mudiraj assigned you a to-do item na

我有一个列表对象。我正在传递给Gson的那个列表

        Gson gson = new Gson();
        String toJson = gson.toJson(userDetailFeedNotifierVoList);
        System.out.println("Gson Object : " + toJson);
我现在进入控制台:

[
{
    "title": "Suman Mudiraj assigned you a to-do item named test todo in the Launch GALAXY activity.",
    "time": "2014-10-08T10:51:07.095Z",
    "url": "https://greenhouse.lotus.com/activities/service/html/mainpage#activitypage,0c7b1fb5-a87f-4112-9b7f-67ed6bd0233f,entry=634e9535-ba17-40da-a242-bd9caff6f17d",
    "schedullarTime": 0
},
{
    "title": "Suman Mudiraj assigned you a to-do item named test todo in the Launch GALAXY activity.",
    "time": "2014-10-08T10:51:07.095Z",
    "url": "https://greenhouse.lotus.com/activities/service/html/mainpage#activitypage,0c7b1fb5-a87f-4112-9b7f-67ed6bd0233f,entry=634e9535-ba17-40da-a242-bd9caff6f17d",
    "schedullarTime": 0
}
]


我想在这里获得标题和url。您能给我建议吗?

如果您只需要特定字段,您可以在这些字段上使用
@Expose

class UserDetailFeedNotifierVo
{
   @Expose
   String title;

   @Expose
   String url;

   //not exposed
   String time;
}
要使用它:

Gson gson = GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
String toJson = gson.toJson(userDetailFeedNotifierVoList);
System.out.println("Gson Object : " + toJson);

您必须向类中不希望序列化的成员添加
transient
修饰符

  // will be serialized
  private String propertyOne;

  // will not be serialized
  private transient String propertyTwo;

如果要将字段从序列化过程中排除,可以将字段标记为瞬态,也可以使用@Expose注释。这个Userdetails是bean类还是什么?这里我必须编写注释或what/@mdrazi那么
userDetailFeedNotifierVoList
的数据类型是什么?List@mdrazi因此
UserDetail
相当于你的
userdetailfeednotifierpolist
类。我已经提到。。。List userDetailFeedNotifierVoList=null@邹州