利用fastjson转换,pom文件依赖:
- <dependency>
- <groupId>dom4jgroupId>
- <artifactId>dom4jartifactId>
- <version>1.6.1version>
- dependency>
- <dependency>
- <groupId>com.alibabagroupId>
- <artifactId>fastjsonartifactId>
- <version>1.2.68version>
- dependency>
工具类
- import com.alibaba.fastjson.JSONArray;
- import com.alibaba.fastjson.JSONObject;
- import org.dom4j.*;
-
- import java.util.List;
-
- public class test {
- /**
- * String 转 org.dom4j.Document
- *
- * @param xml
- * @return
- * @throws DocumentException
- */
- public static Document strToDocument(String xml) {
- try {
- //加上xml标签是为了获取最外层的标签,如果不需要可以去掉
- return DocumentHelper.parseText("
" + xml + ""); - } catch (Document