public static String ConvertXMLtoJSON("f:/test.xml"){ json
// 獲取xml字符串 app
String xml = getXMLString(filePath); xml
// 序列化 字符串
XMLSerializer xmlSerializer = new XMLSerializer(); get
// 把xml內容轉成json io
JSON json = xmlSerializer.read(xml); test
return json.toString(2); file
}private static String getXMLString(String filePath) { 序列化
StringBuffer sb = new StringBuffer(); static
BufferedReader br = null;
String line;
try {
InputStreamReader isr = new InputStreamReader(new FileInputStream(
filePath), "UTF-8");
br = new BufferedReader(isr);
while (true) {
line = br.readLine();
if (line == null) {
break;
}sb.append(line + "\n");
}
} catch (Exception e) {e.printStackTrace();
}
return sb.toString();
}