Let's start off by pointing out that the data provided is not in JSON format.
However, for a hypothetical scenario, let's imagine if it were structured as follows:
[{
"name": "jason",
"height": "150cm"
}, {
"name": "henry",
"height": "178cm"
}]
In that case, it would be considered valid JSON.
You could then implement a function similar to this:
If you're using jQuery:
function GenerateTable(jsonString) {
var data = JSON.parse(jsonString);
var table = createElement('table')
.append(
createElement('thead')
.append(
createElement('tr')
.append(
createElement('th').text('Name'),
createElement('th').text('Height')
)
)
);
var body = createElement('tbody');
data.forEach(function(item) {
body
.append(
createElement('tr')
.append(
createElement('td').text(item.name),
createElement('td').text(item.height)
)
);
});
//append body to table and display on the page
}
Alternatively, considering your current code structure:
function GenerateTable(output) {
var jsonData = JSON.parse(output);
var stringBuilder = new StringBuilder();
for (var i = 0; i < jsonData.length; i++) {
stringBuilder.append("<td>" + jsonData[i].name + "</td>");
stringBuilder.append("<td>" + jsonData[i].height + "</td>");
}
}