我正在使用BeanShell Postprocessor将Result和Response数据一起写入csv文件。除了以下问题,一切正常: - 我的响应数据是JSON格式,在写入csv时由于json中存在逗号“,”而被写入不同的列,但我必须在单列中写入整个RESPONSE数据
这是我的代码的外观:
import java.io.File;
import org.apache.jmeter.services.FileServer;
Result = "FAIL";
Response = prev.getResponseDataAsString();
if (Response.contains("{\"status\":true"))
Result = "PASS";
f = new FileOutputStream("C:/Users/Administrator/APIFramework/bean.csv", true);
p = new PrintStream(f);
p.println( vars.get("id") + "," + Result + "," + Response);
p.close();
f.close();
答案 0 :(得分:0)
你需要逃避逗号和双引号。我查了一下它的确有效:
row ="\"";
cell_value = vars.get("id");
row = row +cell_value;
row= row +"\"";
row = row + "," + Result + "," + Response;
p.println(row);
p.close();
f.close();