forked from stleary/JSON-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXml2JsonRun.java
More file actions
28 lines (23 loc) · 776 Bytes
/
Copy pathXml2JsonRun.java
File metadata and controls
28 lines (23 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package org;
import org.json.JSONObject;
import org.json.XML;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
/**
* Created by ozlevka on 10/22/14.
*/
public class Xml2JsonRun {
public static int PRETTY_PRINT_INDENT_FACTOR = 4;
public static void main(String[] args) {
try {
byte[] allBytes = Files.readAllBytes(Paths.get("/home/ozlevka/Downloads/earthquakes.xml"));
String xml = new String(allBytes, 0, allBytes.length, Charset.forName("UTF-8"));
JSONObject obj = XML.toJSONObject(xml);
System.out.println(obj.toString(PRETTY_PRINT_INDENT_FACTOR));
} catch (IOException e) {
e.printStackTrace();
}
}
}