This question already has an answer here:
这个问题已经有了答案:
- Access / process (nested) objects, arrays or JSON 18 answers
- 访问/进程(嵌套)对象、数组或JSON 18答案。
EDIT - What is the purpose of marking a question as duplicate? Earn some points and get a little wiseass kick? You cannot know that this question will not help someone. The answers to the question that this "duplicated" would not have answered my question in my limited knowledge, but the gentleman who answered MY question did. -EDIT
编辑——将问题标记为副本的目的是什么?赢得一些积分,然后得到一点机智的奖励?你不可能知道这个问题对某人没有帮助。对于这个“重复”的问题的答案,在我有限的知识中不会回答我的问题,但回答我问题的那位先生确实回答了。编辑
I am looking to select just one value from a list of JSON data, the 24 hr price percentage change:
我希望从JSON数据列表中选择一个值,24小时价格百分比变化:
{
"id": "stellar",
"name": "Stellar",
"symbol": "XLM",
"rank": "6",
"price_usd": "0.570132",
"price_btc": "0.00005009",
"24h_volume_usd": "672209000.0",
"market_cap_usd": "10187093680.0",
"available_supply": "17867956333.0",
"total_supply": "103629819514",
"max_supply": null,
"percent_change_1h": "1.8",
"percent_change_24h": "16.65",
"percent_change_7d": "23.95",
"last_updated": "1516839244"
}
and at the moment, my current code, which is just to test if what I have thus far works at all, returns simply [object Object]
:
目前,我目前的代码只是为了测试到目前为止我的代码是否有效,它只返回简单的[object]:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$.getJSON('https://api.coinmarketcap.com/v1/ticker/stellar/',
function (data) {
document.body.append(data);
});
});
</script>
I want to isolate - and to start, just to show - only that "percent_change_24h"
and work from there.
我想要分离-并且开始,只是为了显示-只有那个百分比-改变e_24h然后从那里开始工作。
Thank you.
谢谢你!
2 个解决方案
#1
1
https://api.coinmarketcap.com/v1/ticker/stellar/ returns the array:
https://api.coinmarketcap.com/v1/ticker/stellar/返回的数组:
[
{
"id": "stellar",
"name": "Stellar",
"symbol": "XLM",
"rank": "6",
"price_usd": "0.566242",
"price_btc": "0.00004991",
"24h_volume_usd": "674523000.0",
"market_cap_usd": "10117586651.0",
"available_supply": "17867955133.0",
"total_supply": "103629819514",
"max_supply": null,
"percent_change_1h": "-0.26",
"percent_change_24h": "16.45",
"percent_change_7d": "21.53",
"last_updated": "1516840744"
}
]
So in order to get access to the percent_change_24h
field you need data[0].percent_change_24h
因此,为了访问percent_change_24h字段,需要数据[0].percent - change_24h
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$.getJSON('https://api.coinmarketcap.com/v1/ticker/stellar/',
function (data) {
document.body.append(data[0].percent_change_24h);
});
});
</script>
#2
2
Well, you can access directly using that key percent_change_24h
:
你可以直接使用这个百分比- change_24h键进行访问:
var data = {
"id": "stellar",
"name": "Stellar",
"symbol": "XLM",
"rank": "6",
"price_usd": "0.570132",
"price_btc": "0.00005009",
"24h_volume_usd": "672209000.0",
"market_cap_usd": "10187093680.0",
"available_supply": "17867956333.0",
"total_supply": "103629819514",
"max_supply": null,
"percent_change_1h": "1.8",
"percent_change_24h": "16.65",
"percent_change_7d": "23.95",
"last_updated": "1516839244"
};
console.log(data['percent_change_24h']);
document.body.append(data['percent_change_24h']);
// in your case document.body.append(data['percent_change_24h']);
Hope it helps!
希望它可以帮助!
#1
1
https://api.coinmarketcap.com/v1/ticker/stellar/ returns the array:
https://api.coinmarketcap.com/v1/ticker/stellar/返回的数组:
[
{
"id": "stellar",
"name": "Stellar",
"symbol": "XLM",
"rank": "6",
"price_usd": "0.566242",
"price_btc": "0.00004991",
"24h_volume_usd": "674523000.0",
"market_cap_usd": "10117586651.0",
"available_supply": "17867955133.0",
"total_supply": "103629819514",
"max_supply": null,
"percent_change_1h": "-0.26",
"percent_change_24h": "16.45",
"percent_change_7d": "21.53",
"last_updated": "1516840744"
}
]
So in order to get access to the percent_change_24h
field you need data[0].percent_change_24h
因此,为了访问percent_change_24h字段,需要数据[0].percent - change_24h
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function () {
$.getJSON('https://api.coinmarketcap.com/v1/ticker/stellar/',
function (data) {
document.body.append(data[0].percent_change_24h);
});
});
</script>
#2
2
Well, you can access directly using that key percent_change_24h
:
你可以直接使用这个百分比- change_24h键进行访问:
var data = {
"id": "stellar",
"name": "Stellar",
"symbol": "XLM",
"rank": "6",
"price_usd": "0.570132",
"price_btc": "0.00005009",
"24h_volume_usd": "672209000.0",
"market_cap_usd": "10187093680.0",
"available_supply": "17867956333.0",
"total_supply": "103629819514",
"max_supply": null,
"percent_change_1h": "1.8",
"percent_change_24h": "16.65",
"percent_change_7d": "23.95",
"last_updated": "1516839244"
};
console.log(data['percent_change_24h']);
document.body.append(data['percent_change_24h']);
// in your case document.body.append(data['percent_change_24h']);
Hope it helps!
希望它可以帮助!