Skip to content

Commit 44adc1c

Browse files
author
Levka
committed
Create working example
1 parent 7d2e1c1 commit 44adc1c

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
*.class
33
*.log
44
*.iml
5+
out/

org/Xml2JsonRun.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org;
2+
3+
import org.json.JSONObject;
4+
import org.json.XML;
5+
6+
import java.io.IOException;
7+
import java.nio.charset.Charset;
8+
import java.nio.file.Files;
9+
import java.nio.file.Paths;
10+
11+
/**
12+
* Created by ozlevka on 10/22/14.
13+
*/
14+
public class Xml2JsonRun {
15+
public static int PRETTY_PRINT_INDENT_FACTOR = 4;
16+
17+
18+
public static void main(String[] args) {
19+
try {
20+
byte[] allBytes = Files.readAllBytes(Paths.get("/home/ozlevka/Downloads/earthquakes.xml"));
21+
String xml = new String(allBytes, 0, allBytes.length, Charset.forName("UTF-8"));
22+
JSONObject obj = XML.toJSONObject(xml);
23+
System.out.println(obj.toString(PRETTY_PRINT_INDENT_FACTOR));
24+
} catch (IOException e) {
25+
e.printStackTrace();
26+
}
27+
}
28+
}

0 commit comments

Comments
 (0)