package com.say.bean;
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.json.*;
public class JsonUtils {
/**
* xml文件解析成json字符串
* @return json字符串
* @throws JSONException
* @throws IOException
*/
public static String xml2jsonString() throws JSONException, IOException {
InputStream in = JsonUtils.class.getResourceAsStream("test1.xml");
String xml = IOUtils.toString(in);
JSONObject xmlJSONObj = XML.toJSONObject(xml);
return xmlJSONObj.toString();
}
public static void main(String[] args) throws JSONException, IOException {
String string = xml2jsonString();
System.out.println(string);
}
}
java:xml解析成json
猜你喜欢
转载自blog.csdn.net/weixin_42170236/article/details/102966915
今日推荐
周排行