簡體   English   中英

Java中的JSON數組解析

[英]JSON array parsing in java

這是我的代碼

String json = "{product:{\"controls\": [[\"fire\", \"na\"], [\"jump\", \"na\"], [\"movement\", \"arrow\"]], \"languages\": [\"en\",\"br\"]}}";
XStream xstream = new XStream(new JettisonMappedXmlDriver());
xstream.alias("product", Product.class);
Product product = (Product)xstream.fromXML(json);
System.out.println(product);

但是我收到這個錯誤

Exception in thread "main" com.thoughtworks.xstream.converters.reflection.AbstractReflectionConverter$DuplicateFieldException: controls
---- Debugging information ----
duplicate-field     : controls
class               : Product
required-type       : Product
path                : /product/controls[2]
line number         : -1
-------------------------------

該代碼適用於非數組數據。

我該如何解決?

對arraylists類成員使用注釋,例如:

@XStreamImplicit
private List<String> content;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM