Created
September 22, 2020 08:39
-
-
Save cuongld2/2ee49c91bb560453101a5ebbe0834906 to your computer and use it in GitHub Desktop.
Parse json from API to data structures in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern crate reqwest; | |
extern crate tokio; | |
extern crate serde_json; | |
extern crate serde; | |
use serde::{Serialize, Deserialize}; | |
#[derive(Deserialize, Debug)] | |
struct SearchElement{ | |
auth_resource_path: String, | |
field: String, | |
id: String, | |
project_id: String, | |
#[serde(rename = "type")] | |
typepp: String, | |
value: String, | |
} | |
#[tokio::main] | |
async fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let res = reqwest::Client::builder() | |
.danger_accept_invalid_certs(true) | |
.build() | |
.unwrap() | |
.get("ssl_certificate_error") | |
.send().await?; | |
let json_value: Vec<SearchElement> = res.json().await?; | |
println!("{:?}",json_value); | |
for i in &json_value{ | |
println!("{:?}", i.auth_resource_path); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment