rust - 如何从 Reqwest 响应中获取 API 的 JSON 数据?
问题描述
我想从 API 获取数据:
extern crate reqwest;
use std::io::Read;
pub fn main() {
let mut response = reqwest::get("https://api.fcoin.com/v2/market/ticker/ftbtc")
.expect("Failed to send request");
let mut buf = String::new();
response
.read_to_string(&mut buf)
.expect("Failed to read response");
println!("{}", buf);
}
输出是
{
"status": 0,
"data": {
"ticker": [
0.00006173,
500,
0.00006173,
44411.28,
0.00006174,
917.98,
0.00008033,
0.00008654,
0.00006026,
7144217252.9,
554239.7346328925
],
"type": "ticker.ftbtc",
"seq": 2995173
}
}
我可以将buf
or 响应转换为 key => value 样式Vec
或数组吗?
解决方案
推荐阅读
- python - 将 sas7bdat 文件上传到 Python
- github - 在 github 问题中嵌入大型或非标准文件
- angular - 从 firebase 获取文档并访问函数返回的数据
- floating-point - Common Lisp 中浮点数的字节表示
- javascript - sequelize.literal 返回原始属性名称和重命名后的属性
- sql - 如何计算另一个表中连接查询的结果值?
- php - 在 woocommerce 上为免费物品创建运输方式
- excel - 在 VBA 中使用 selection.currentregion 在另一张表中进行 vlookup
- python - python如何在交互式解释器与jupyter笔记本中实习字符串
- mysql - 有没有一种解决方案可以在没有左连接的情况下从 2 个表中获取数据?