简体   繁体   English

从API导入特定数据?

[英]Import Specific Data From API?

I found this little "API" that I want to take data from. 我找到了我要从中获取数据的这个小“ API”。

https://www.bitstamp.net/api/ticker/ https://www.bitstamp.net/api/ticker/

Basically, I want to take the value "ask" and use it in HTML. 基本上,我想取值“ ask”并在HTML中使用它。 From the 7 values there, how do I specifically target the "ask" price and nothing else? 从那里的7个值中,我如何专门针对“问价”而不是其他? I just want the number. 我只想要电话号码。

The API returns API返回

{"high": "849.00", "last": "847.59", "timestamp": "1385491132", "bid": "847.59", "volume": "31642.03534404", "low": "770.10", "ask": "848.00"}

Sorry, I know I sound horribly dumb, I am still new to this. 抱歉,我知道我听起来很傻,我对此还很陌生。

That data is returned as JSON string, you can use JSON.parse to extract needed property. 该数据以JSON字符串形式返回,您可以使用JSON.parse提取所需的属性。

Let's say you want to display value in this element: 假设您要在此元素中显示值:

<input type="text" id="ask" />

The code would be: 该代码将是:

// simulated value, in reality result of API call
var sResult = '{"high": "849.00", "last": "847.59", "timestamp": "1385491132", "bid": "847.59", "volume": "31642.03534404", "low": "770.10", "ask": "848.00"}'

var jsResult = JSON.parse(sResult);

document.getElementById("ask").value = jsResult.ask;

Demo: http://jsfiddle.net/qfY6s/ 演示: http//jsfiddle.net/qfY6s/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM