GSON忽略JSON场和反序列化 [英] Gson ignore json field and deserialize
本文介绍了GSON忽略JSON场和反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在与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.
这篇关于GSON忽略JSON场和反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文