GSON忽略JSON场和反序列化序列化、GSON、JSON

2023-09-07 13:49:10 作者:挂在树上的骷髅。

我正在与Android和GSON,我想知道如果我能忽略来自Web服务领域。

I'm working with android and gson and i was wondering if i can ignore a field from the webservice.

此其我GSON对象

Gson gson = new GsonBuilder().serializeNulls().create();

所以,我需要的是忽略验证领域和反序列化到我的自定义豆以下code。

So what i need is to ignore validator field and deserialize to my custom bean in the following code.

它没有办法做到这一点与GSON?

Its any way to do that with gson ?

{ "posts":
  [      

        {
       "username": "John",  
       "message": "I'm back",
       "time": "2010-5-6 7:00:34"
        "validator":[{
                        "prog": "Name1",
                        "name": "Name2",
                        "computername": "Name3",
                        "date": "2010-11-20 19:39:55"
                      }]
        }
      ,

        {
          "username": "Smith",
          "message": "I've been waiting",
          "time": "2010-4-6 10:30:26"
           "validator":[{
                        "prog": "Name1",
                        "name": "Name2",
                        "computername": "Name3",
                        "date": "2010-11-20 19:39:55"
                      }]

       }
]}

在此先感谢

干杯

推荐答案

您可以致电 gson.fromJson(inputString,localObject)如果localObject未声明的验证变量,它会跳过它。

You can call gson.fromJson(inputString, localObject) and if localObject doesn't declare a validator variable, it will just skip it.