0

I have the following Json data :-

[{"accountid":"1-RMNT","name":"NASA"},
{"accountid":"1-XQN9","name":"NewAccount"},
{"accountid":"1-Q9VF","name":"Noratel Communication"},
{"accountid":"1-RNLY","name":"Nordstrom"}]

How can I convert this JSON data to XML? Any suggestions would be appreciated.

Jacob
  • 41,721
  • 6
  • 79
  • 81
Bie
  • 1
  • 1

4 Answers4

1

You can check the class XML.java that it´s be included in the package org.jason.

Lukas Knuth
  • 25,449
  • 15
  • 83
  • 111
luisgarcia
  • 11
  • 1
1

I don't have a direct solution, but using gson(JSON to object) and xstream(object to XML) is doable. It may need some extra mapping code.

Jerry Tian
  • 3,439
  • 4
  • 27
  • 29
0

Do not think difficult, Its a easy way to convert XML to JSON or JSON to XML, Just open http://www.utilities-online.info/xmltojson/ and paste your json codes or xml codes. After paste and press button, then you will get Output. Its very useful for you.

It's Me SMA
  • 71
  • 2
  • 9
0

Underscore-java has method U.jsonToXml(json).

import com.github.underscore.U;

public class Test {
    public static void main(String[] args) throws Exception {
        String json = "[{\"accountid\":\"1-RMNT\",\"name\":\"NASA\"},\n"
            + "{\"accountid\":\"1-XQN9\",\"name\":\"NewAccount\"},\n"
            + "{\"accountid\":\"1-Q9VF\",\"name\":\"Noratel Communication\"},\n"
            + "{\"accountid\":\"1-RNLY\",\"name\":\"Nordstrom\"}]";
        System.out.println(U.jsonToXml(json));
    }
}

// <?xml version="1.0" encoding="UTF-8"?>
// <root>
//   <element>
//     <accountid>1-RMNT</accountid>
//     <name>NASA</name>
//   </element>
//   <element>
//     <accountid>1-XQN9</accountid>
//     <name>NewAccount</name>
//   </element>
//   <element>
//     <accountid>1-Q9VF</accountid>
//     <name>Noratel Communication</name>
//   </element>
//   <element>
//     <accountid>1-RNLY</accountid>
//     <name>Nordstrom</name>
//   </element>
// </root>
Valentyn Kolesnikov
  • 2,029
  • 1
  • 24
  • 31