代码块
//前端组装json串:
var allInfor= {};
var suiteInfo = $("#suiteInfoJmeter").val();
if(suiteInfo != ''){
var suiteArray = suiteInfo.split(";");
var bindhosts = new Array();
var ipArray = {};
for(var i=0; i<suiteArray.length; i++)
{
var array = suiteArray[i].split(" ");
ipArray.hostname = array[0];
ipArray.IP = array[1];
bindhosts.push(ipArray);
}
allInfor.bindhosts=bindhosts;
};
//将String转成json对象:
var allInforString = $("#allInfor").val();
if(allInforString != ''){
allInfor = $.parseJSON(allInforString);
};
//遍历json对象:
var json = eval(allInfor.scriptfiles);
if(json != null){
for(var i=0; i < json.length; i++)
{
var md5 = json[i].fileMd5;
if(tid == md5){
json.splice(i,1); //删除json对象中某个值;
}
}
};
//将json对象转成String:
JSON.stringify(allInfor);
//后台解析json串
String newInfo = testSuite.getSuiteInfo();
JSONObject newSuiteInfo = JSON.parseObject(newInfo);//将String转成json对象
JSONArray newDatafilesArray = newSuiteInfo.getJSONArray("datafiles");//获取json数组
if (newDatafilesArray != null && newDatafilesArray.size() > 0) {
for (int i = 0; i < newDatafilesArray.size(); i++) {
ScriptBO scriptBO = new ScriptBO();
JSONObject newDatafileObject = (JSONObject)newDatafilesArray.get(i);//获取数组值
scriptBO.setFileName(newDatafileObject .getString("fileName"));
scriptBO.setRecycle(newDatafileObject .getIntValue("recycle"));
scriptBO.setCreateAt(newDatafileObject .getString("createAt"));
scriptBO.setFileMd5(newDatafileObject .getString("fileMd5"));
}
}
//将json对象转成String
JSONObject newJsonObject = new JSONObject();
newJsonObject..toString();