xStream JSON - 如何处理空值 [英] xStream JSON - how to handle null values
本文介绍了xStream JSON - 如何处理空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个 json 示例:
I've this json example:
{
"rows": [
{
"anaid": "1",
"anaint": "123",
"anastring": "-"
},
{
"anaid": "2",
"anaint": "-",
"anastring": "Hello World"
},
{
"anaid": "3",
"anaint": "-",
"anastring": "-"
}
]
}
我的班级测试在哪里:
- 内部援助
- int anint
- 字符串字符串
我的java代码:
XStream xstream = new XStream(new JettisonMappedXmlDriver());
xstream.alias("rows", Test.class);
ArrayList<Test> product = (ArrayList<Test>) xstream.fromXML(json);
所以字符-"是我的 json 的空值.我无法更改代码来创建 json,但我会处理-"空值以正确使用我的 xStream 解析器.
So the character "-" is the null value for my json. I can't change the code to create json, but I would handling the "-" null value to use correctly my xStream parser.
推荐答案
使用自定义转换器.教程这里
Use a custom converter. Tutorial here
这篇关于xStream JSON - 如何处理空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文