feat: create struct from json response and create a table view
This commit is contained in:
+1
-1
@@ -10,7 +10,7 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
ui.on_request_text_input(|text| {
|
||||
println!("User input: {}", text);
|
||||
let response = rutracker::search(&text);
|
||||
let _response = rutracker::search(&text);
|
||||
});
|
||||
|
||||
ui.run()?;
|
||||
|
||||
@@ -1,5 +1,16 @@
|
||||
use serde_derive::Deserialize;
|
||||
use serde_derive::Serialize;
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Software {
|
||||
pub author: String,
|
||||
pub leechers: String,
|
||||
pub seeders: String,
|
||||
pub title: String,
|
||||
pub url: String,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
|
||||
let api_url = "https://api.michijackson.xyz/search?q=".to_owned();
|
||||
@@ -7,6 +18,11 @@ pub async fn search(value: &str) -> Result<Value, reqwest::Error> {
|
||||
let text = results.text().await?;
|
||||
let v: Value = serde_json::from_str(&text).expect("Failed to parse JSON");
|
||||
let data = &v["data"];
|
||||
for item in data.as_array().unwrap() {
|
||||
let software: Software =
|
||||
serde_json::from_value(item.clone()).expect("Failed to deserialize");
|
||||
println!("{:?}", software);
|
||||
}
|
||||
println!("{:?}", data);
|
||||
Ok(v)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user