小编典典
Java中的 JSON有一些很棒的资源。
Maven依赖项:
org.json
json
20180813
XML.java 是您要寻找的课程:
import org.json.JSONObject;
import org.json.XML;
public class Main {
public static int PRETTY_PRINT_INDENT_FACTOR = 4;
public static String TEST_XML_STRING =
"<?xml version=\"1.0\" ?>Turn this to JSON";
public static void main(String[] args) {
try {
JSONObject xmlJSONObj = XML.toJSONObject(TEST_XML_STRING);
String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
System.out.println(jsonPrettyPrintString);
} catch (JSONException je) {
System.out.println(je.toString());
}
}
}
输出为:
{"test": {
"attrib": "moretest",
"content": "Turn this to JSON"
}}
2020-03-01