2

I want to get the data from an 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);
}

The output is

{
  "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
  }
}

Can I transfer the buf or response into a key => value style Vec or array?

Stargateur
  • 24,473
  • 8
  • 65
  • 91
jie zhang
  • 69
  • 8
  • I believe your question is answered by the answers of [How do I parse a JSON File?](https://stackoverflow.com/q/30292752/155423) (specifically the answer using Serde. If you disagree, please [edit] your question to explain the differences. Otherwise, we can mark this question as already answered. – Shepmaster Jun 22 '18 at 02:51

0 Answers0