我试图从这个端点https://prices.runescape.wiki/api/v1/osrs/latest中提取JSON.
#[derive(Serialize, Deserialize, Debug)]
struct Latest {
high: u32,
highTime: String,
low: String,
lowTime: String,
}
#[derive(Serialize, Deserialize, Debug)]
struct Data {
#[serde(with = "serde_with::json::nested")]
data: Vec<Latest>,
}
#[derive(Serialize, Deserialize, Debug)]
struct Datav2 {
#[serde(with = "serde_with::json::nested")]
data: HashMap<u32, Vec<Latest>>,
}
#[cfg(not(target_arch = "wasm32"))]
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let res = reqwest::get(url).await?;
let response = &res.json::<Datav2>().await?;
}
我try 了两个版本的数据 struct .数据使用的是一个最新的向量,但我注意到每个对象都有一个唯一的ID,所以在DataV2中,我try 使用hashmap,但得到了相同的错误.我还try 了不使用Serde\u的不受欢迎的版本.
我得到错误Error: reqwest::Error { kind: Decode, source: Error("invalid type: map, expected valid json object", line: 1, column: 8)
看起来我的数据 struct 一团糟,但我已经花了几个小时试图找出要使用的正确数据 struct .