1
I have the following sample HTML:
<tr>
<td>Futebol</td>
<td>Campo</td>
</tr>
<tr>
<td>Volei</td>
<td>Quadra</td>
</tr>
<tr>
<td>Tenis</td>
<td>Saibro</td>
<td>Campo</td>
</tr>
<tr>
<td>Natação</td>
<td>Piscina</td>
</tr>
<tr>
<td>Ciclismo</td>
<td>Rua</td>
</tr>
I would need to go through the tr
taking the value of each td
and have a json
sort of like this:
"esportes":[
{
"esporte":"Futebol",
"ambiente":"Campo"
},
{
"esporte":"Volei",
"ambiente":"Quadra"
},
{
"esporte":"Tenis",
"ambiente":"Saibro",
"ambiente":"Campo"
},
{
"esporte":"Ciclimo",
"ambiente":"Rua"
}]
How could I do that to jQuery? I did just that for now but do not know how to continue from here (if I am in the way). Turning to JSON is not quite the problem, the biggest problem would be to take the values in the right way, each sport with its use environment:
$("#tableEsportes > tbody > tr").each(function(){
console.log($(this).text());
});
Useful link: https:/jsonlint.com allows you to validate your json with a brief explanation about Json
– Caique Romero