xmind解析为json:
https://blog.csdn.net/QQlwx/article/details/105827376
json转case:
下面代码将如图json转为case,并输出
package com.xxx.xmind;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.compress.archivers.ArchiveException;
import org.dom4j.DocumentException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* @author
*/
public class XmindToCase {
private static List<String> list = new ArrayList<>();
private static List<String> result = new ArrayList<>();
public static void main(String[] args) throws DocumentException, ArchiveException, IOException {
JSONObject xmindJson = paserXmind("out/aotuTest.xmind");
System.out.println(xmindJson.toJSONString());
if (!xmindJson.containsKey("code")) {
dealChildren(xmindJson);
System.out.println(list.toString());
System.out.println(result.toString());
}else{
System.out.println("get path fail");
}
}
public static void dealChildren(JSONObject jsonObject) {
getTitle(jsonObject);
if (jsonObject.containsKey("children")) {
JSONObject children = jsonObject.getJSONObject("children");
if (children.containsKey("attached")) {
// depth++;
JSONArray attached = children.getJSONArray("attached");
for (int i = 0; i < attached.size(); i++) {
dealChildren(attached.getJSONObject(i));
}
//执行完把本节点删除
list.remove(list.size() - 1);
}
} else {
//到达叶子节点,进行输出
String temp = "";
int len = list.size();
for (int i = 0; i < len-1; i++) {
temp += list.get(i) + "-";
}
temp += list.get(len-1);
result.add(temp);
list.remove(list.size() - 1);
}
}
public static void getTitle(JSONObject jsonObject) {
String title = jsonObject.getString("title");
list.add(title);
}
public static JSONObject paserXmind(String path) throws DocumentException, ArchiveException, IOException {
JSONObject k;
if (path != null && path.length() > 0) {
String res = ParserXmind.parseJson(path);
k = JSONObject.parseObject(res).getJSONObject("rootTopic");
} else {
k = JSONObject.parseObject("{\"code\":1}");
}
return k;
}
}