I'm trying to create a table for a football league with the return of a json:
To facilitate I will put the Json below refers only to a Team:
{
"id": "1",
"nome": "Palmeiras",
"Atleta": [
{
"id": "0",
"nome": "Fernando Prass",
"idade": "1",
"FichaTecnica": [
{
"id": "1",
"posicao": "goleiro",
"camisa": "12"
},
{
"id": "2",
"posicao": "zaga",
"camisa": "11"
},
{
"id": "3",
"posicao": "meia",
"camisa": "9"
},
{
"id": "4",
"posicao": "zaga",
"camisa": "7"
},
{
"id": "5",
"posicao": "meia",
"camisa": "5"
},
{
"id": "6",
"posicao": "ataque",
"camisa": "3"
}
]
}
]
}{
'id': '2',
'nome': 'Conrinthias',
'Atleta': [
{
'id': '0',
'nome': 'Cássio',
'idade': '1',
'FichaTecnica': [
{
'id': '1',
'posicao': 'goleiro',
'camisa': '1'
},
{
'id': '2',
'posicao': 'zaga',
'camisa': '22'
},
{
'id': '3',
'posicao': 'meia',
'camisa': '5'
},
{
'id': '4',
'posicao': 'zaga',
'camisa': '7'
},
{
'id': '5',
'posicao': 'meia',
'camisa': '8'
},
{
'id': '6',
'posicao': 'ataque',
'camisa': '6'
}
]
}
]
}
The code to read Json is as follows:
@section Scripts{
<script type="text/javascript">
$(document).ready(function () {
var valorRetornado= //É o Json exemplificado acima.
// convertendo a string em objeto
var obj = JSON.parse(valorRetornado);
obj.forEach(function (o, index) {
console.log(o.id);
});
});
</script>
}
The problem I'm facing is the following error:
Uncaught ReferenceError: valorRetornado is not defined
at HTMLDocument.<anonymous> (Index:61)
at fire (jquery-1.10.2.js:3062)
at Object.fireWith [as resolveWith] (jquery-1.10.2.js:3174)
at Function.ready (jquery-1.10.2.js:447)
at HTMLDocument.completed (jquery-1.10.2.js:118)