XML 到 Json 没有按照我期望的方式处理数组
我有一个 api,可以使用 XML 或 Json 格式进行响应。为了分析这些结果,我创建了一个要填充 json 和 xml 的对象。问题是我的 XML 解析器似乎以稍微不同的格式将 XML 反序列化为 Json。
我的回复中间是一个嵌套数组 当我解析 JSON 时,看起来像这样
"buckets":[
{"bucket":{"name":"soup","priority":10}},
{"bucket":{"name":"clams","priority":13}}],
当我将 XML 解析为 JSON 时,它看起来像这样
"buckets":{"bucket":[
{"priority":"10","name":"soup"},
{"priority":"13","name":"clams"}]},
我为保存此日期而创建的单个对象有一个私有列表桶; json 解析处理得很好,而 xml 解析会抛出异常。
我将两者解析为对象,如下所示 myObject = mapper.readValue(SomeObject.get(0),myObject.class)
json 存储桶工作正常,而 xml 则不行。我要么需要将 XML 解析为与 json 类似的格式,要么用注释告诉它可以正确查看存储桶
我使用此 JSONObject jsonObject = XML.toJSONObject(cValue); 将 XML 解析为 json;
I have an api that can have its response in either XML or Json. For analyzing those results I created a single object that I want to populate for both json and xml. Problem is my XML parser seems to deserialize the XML into Json in a slightly different format.
In the middle of my response is a nested array
when I parse the JSON is looks like so
"buckets":[
{"bucket":{"name":"soup","priority":10}},
{"bucket":{"name":"clams","priority":13}}],
And when I parse my XML to JSON it looks like so
"buckets":{"bucket":[
{"priority":"10","name":"soup"},
{"priority":"13","name":"clams"}]},
My single object created to hold this date has a private List buckets; Which the json parse handles fine while the xml parse throws an exception.
I am parsing both to the object like so
myObject = mapper.readValue(SomeObject.get(0),myObject.class)
The json buckets works fine the xml does not. I either need to parse the XML into similar format as the json or tell it maybe with an annotation to see buckets correctly
I parse my XML to json with this JSONObject jsonObject = XML.toJSONObject(cValue);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论