【发布时间】:2016-02-23 10:42:23
【问题描述】:
我有一个这样的 JSON 文件,保存为 runs.json,我想使用 ajax 调用 json 文件,但我真正想要的 json 值没有反复显示,我没有定义
{
"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