Skip to content

Instantly share code, notes, and snippets.

@cuongld2
Created September 22, 2020 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cuongld2/2ee49c91bb560453101a5ebbe0834906 to your computer and use it in GitHub Desktop.
Save cuongld2/2ee49c91bb560453101a5ebbe0834906 to your computer and use it in GitHub Desktop.
Parse json from API to data structures in Rust
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