Jettison を使用して JSON オブジェクトを解析しようとしています。これは私が使用しているコードです
String s ="{\"appUsage\":[{\"appName\":\"ANDROID\",\"totalUsers\":\"0\"},{\"appName\":\"IOS\",\"totalUsers\":\"4\"}]}";
JSONObject obj = new JSONObject(s);
ArrayList<MiAppUsage> l1 = (ArrayList<MiAppUsage>) jsonParser(ArrayList.class, obj);
public static Object jsonParser(Class c, JSONObject obj)
throws JSONException, XMLStreamException, JAXBException {
JAXBContext jc = JAXBContext.newInstance(c);
Configuration config = new Configuration();
MappedNamespaceConvention con = new MappedNamespaceConvention(config);
XMLStreamReader xmlStreamReader = new MappedXMLStreamReader(obj, con);
Unmarshaller unmarshaller = jc.createUnmarshaller();
ArrayList<MiAppUsage>customer = (ArrayList<MiAppUsage>) unmarshaller.unmarshal(xmlStreamReader);
return customer;
}
このエラーが発生しています
スレッド「メイン」での例外 javax.xml.bind.UnmarshalException - リンクされた例外: [javax.xml.bind.UnmarshalException: 予期しない要素 (uri:""、local:"appUsage")。予想される要素は、com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.handleStreamException(Unknown Source) の (none)] です。 unmarshal0 (不明なソース) com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal (不明なソース) com.json.UnmarshalDemo.jsonParser(UnmarshalDemo.java:56) com.json.UnmarshalDemo .main(UnmarshalDemo.java:33) 原因: javax.xml.bind.UnmarshalException: 予期しない要素 (uri:""、local:"appUsage")。予想される要素は、com.sun.xml.internal.bind.v2 で (なし) です。v2.runtime.unmarshaller.StAXStreamConnector.handleStartElement(Unknown Source) at com.sun.xml.internal.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(Unknown Source) ... さらに 4 原因: javax.xml.bind .UnmarshalException: 予期しない要素 (uri:""、local:"appUsage")。期待される要素は (なし) ... 14 以上
この問題を解決する方法