我有一個像這樣保存爲runs.json的JSON文件,我想使用ajax調用json文件,但是我實際想要從json獲得的值不會反覆顯示我越來越不確定如何從JSON API調用值
{
"status": "true",
"Content-Range": {
"AthletesRange": [
{
"first": "1",
"last": "1",
"max": "1"
}
]
},
"data": {
"Athletes": [
{
"AthleteID": "600",
"FirstName": "Edward",
"LastName": "HAWTHORNE",
"HomeRunID": "1",
"Sex": "M",
"CountryCode": "97",
"Avatar": "images.parkrun.com/app/general/parkrun_default_avatar_200x200.png"
}
]
},
"links": [
{
"rel": "self",
"href": "\"/v1/athletes/600?offset=0&limit=100\""
}
],
"timestamp": 1456223662,
"originalQryTime": 1456223662
}
My AJAX call is like this
<script>
$(document).ready(function(){
$.ajax({
type: "GET",
url: "runs.json",
dataType: 'json',
success: function(result){
var first = result.FirstName;
var last = result.LastName;
$('#runner-name').append(' Welcome ' + first + last);
}
});
});
</script>
<body>
<div>
<h1 id="runner-name"></h1>
</div>
</body>
But am continually getting undefined as the value passed out, I would like if anyone could help me with this JSON call because i need the FirstName and LastName of the particular Athlete.
'result.data.Athletes [0] .FirstName' – Nemoden