[英]Cleanest way to deserialize a non-standard (wrong) format of list of JSON string that doesn't have quote
I'm trying to deserialize a Java String
to a List
of String
.我正在尝试将 Java
String
反序列化为List
of String
。 Due to some reason, the input may come in two formats:由于某种原因,输入可能有两种格式:
"[\"string1\", \"string2\"]"
or或者
"[string1, string2]"
The library I'm using is Jackson databind.我使用的库是 Jackson databind。
For the first case, it's a typical, easy case that Jackson supports.对于第一种情况,这是 Jackson 支持的一个典型的、简单的情况。
For the second, I understand it's not a correct format of JSON and I can hack to achieve the goal by splitting this String
by ,
and remove []
s etc, but just would like to know if someone knows a clean way to deserialize something like that.第二,我知道这不是正确的 JSON 格式,我可以通过将这个
String
拆分为,
并删除[]
s 等来实现目标,但只是想知道是否有人知道反序列化的干净方法,例如那。
Thanks in advance.提前致谢。
To answer your question, you can look into YAML parsers.要回答您的问题,您可以查看YAML解析器。 :)
:)
Jackson has an extention for YAML support so that would be your clean solution. Jackson 对 YAML 支持进行了扩展,因此这将是您的干净解决方案。
YAML is a superset of JSON so it can parse any valid JSON... as well as many more complex transcripts (like strings without "
). YAML 是 JSON 的超集,因此它可以解析任何有效的 JSON……以及许多更复杂的转录本(如没有
"
字符串)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.