POSTMAN JSON转接口文档 Collection v2.1 (recommended)
本代码主要针对“GET”请求和“POST”请求中的 raw->body(json)模式,且导出版本对应Collection v2.1
所需jar包
ExportPostManApiUtil.java
package mango;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
/**
* postman转接口文档html
* zhouy
* 2021-6-10 11:45:48
*/
public class ExportPostManApiUtil {
public static String readToString(String fileName) {
String encoding = "UTF-8";
File file = new File(fileName);
Long fileLength = file.length();
byte[] fileContent = new byte[fileLength.intValue()];
try {
FileInputStream in = new FileInputStream(file);
in.read(fileContent);
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
return new String(fileContent, encoding);
} catch (UnsupportedEncodingException e) {
System.err.println("The OS does not support " + encoding);
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
// readFile("C:\\Users\\Yan\\Desktop\\api\\b.json");
// readFile("C:\\Users\\Yan\\Desktop\\api\\c.json");
// readFile("C:\\Users\\Yan\\Desktop\\api\\d.json");
// readFile("C:\\Users\\Yan\\Desktop\\api\\e.json");
// readFile("C:\\Users\\Yan\\Desktop\\api\\f.json");
readFile("C:\\Users\\acer\\Desktop\\test.json");
}
/**
* 解析postman 导出的Json数据
*
* @param path
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
private static void readFile(String path) {
String file = readToString(path);
Map fileMap = (Map)JSON.parse(file);
Map infoMap = (Map)fileMap.get("info");
List
参考:https://www.cnblogs.com/xsnd/p/8708817.html
原文:https://www.cnblogs.com/zhoumango/p/14870510.html