T157 table converted to json

This commit is contained in:
2021-02-02 13:21:20 +01:00
parent e3d5532397
commit cef945e957
3 changed files with 26 additions and 22 deletions

View File

@@ -66,9 +66,9 @@ function generateHeaderTable(headers){
}
for(let i=0; i<count; i++){
innerHTML+=
'<tr>' +
'<tr class="httpStatusValue">' +
'<td>' +
'<input type="text" name="headerKey" placeholder="key" class="tableField headerName httpStatusValue" value="' + keys[i] + '"/></td>' +
'<input type="text" name="headerKey" placeholder="key" class="tableField headerName" value="' + keys[i] + '"/></td>' +
'<td>' +
'<input type="text" name="headerKey" placeholder="key" class="tableField" value="' + values[i] + '"/></td>' +
'</tr>';
@@ -148,27 +148,20 @@ function generateJson(){
httpStatus: $('#httpStatus').val(),
httpHeaders: {},
};
newJson['httpHeaders'] = convertTableToJson();
document.write(JSON.stringify(newJson, null, 2));
}
// $("table tr").eq(row).find("td").eq(i%2).append("<img src='"+dataJson[i].imagen+"' width='100'/>");
function convertTableToJson(){
var table = $('#headerTable');
console.log("Length of header table: " + table.length);
console.log("Length of children of header table: " + table.children().length);
var hKey = new Array(table.children().length);
var hVal = new Array(table.children().length);
if(table.children().length == 0) return;
for(let i=1; i<table.children.length;i++){
hKey[i-1] = table.eq(i).eq(0).val();
hVal[i-1] = table.eq(i).eq(1).val();
console.log('Key='+hKey[i-1]+' Value='+hVal[i-1]);
var rows = $('.httpStatusValue');
console.log("Rows: "+rows.length);
var obj = {};
var key;
for(let i=0; i<rows.length; i++){
key = rows.eq(i).children().eq(0).children().eq(0).val();
obj[key] = rows.eq(i).children().eq(1).children().eq(0).val();
}
}
//TODO: children is an array
// add class for each row
// divide table into th and tb
// children().eq(0).text()
// jsfiddle.net
return obj;
}

View File

@@ -0,0 +1,12 @@
{
"clientUUID": "9bfddcc1-ef89-4c53-84e8-c88f13ecc7ec",
"mockedResponseId": 1,
"mediaType": "application/xml",
"messageBody": "\n\n Tove\n Jani\n Reminder\n Don't forget me this weekend!\n",
"httpStatus": "200",
"httpHeaders": {
"Keep-Alive": "timeout=60",
"Connection": "keep-alive",
"Date": "2021-02-02T12:15:22.164035"
}
}