杰克逊 - 将JsonNode转换为xml

时间:2017-10-02 08:05:15

标签: java json xml jackson

我想将杰克逊WebView wvUltimo = findViewById(R.id.wv_your_web_view_id); wvUltimo.loadUrl(REQUESTED_WEB_PAGE_URL); // e.g. "https://www.google.com" wvUltimo.getSettings().setJavaScriptEnabled(true); // Only enable this if you need Javascript to work within the WebView!! wvUltimo.setWebChromeClient(new WebChromeClient() { public void onProgressChanged(WebView view, int progress) { // Log.d(TAG + " 185", "Load Status: " + progress); if (progress == 100) { ImageView ivCoolSplash = view.findViewById(R.id.iv_your_splash_screen_id); ivCoolSplash.setVisibility(View.GONE); } } }); 转换为JsonNode

有像xml-to-json这样的反向解决方案。

我的JsonNode:

xml

感谢。

1 个答案:

答案 0 :(得分:1)

看到这个解决方案:

  String responseString = "{\"name\":\"FOO\",\"bar\":{\"id\":42}}";
     ObjectMapper mapper = new ObjectMapper();
     JsonNode node = mapper.readTree(responseString.getBytes());

     ObjectMapper xmlMapper = new XmlMapper();
     String xml = xmlMapper.writeValueAsString(node);
      System.out.println(xml);

输出:

<ObjectNode xmlns=""><name>FOO</name><bar><id>42</id></bar></ObjectNode>