edit:
I complained about this to a friend and he suggested deleting Cargo.lock and letting it regen, and sure enough, it builds just fine now. So I guess that solves that, and now I feel silly for not having thought to try this first.
I'm attempting to use serde_json to, well, deserialize some JSON data and use it to show some information to the user. What's strange is that the compiler is telling me that serde_json::Value
doesn't have the method get
in this scope:
error: no method named `get` found for type `serde_json::Value` in the current scope
--> src/jisho.rs:34:24
|
34 | let data = jisho_json.get("data").unwrap();
| ^^^
That doesn't make sense to me, it's right there in the docs. A similar thing happens when trying to index a Value
:
error: cannot index a value of type `serde_json::Value`
--> src/jisho.rs:34:13
|
34 | let data = jisho_json["data"];
|
Here's the code that doesn't work:
let mut resp = match client.get(url.as_str()).send() {
//...
};
let mut resp_string = String::new();
let _ = resp.read_to_string(&mut resp_string).unwrap();
let jisho_json: Value = serde_json::from_str(resp_string.as_str()).unwrap();
let data = jisho_json["data"];
What makes this even more mysterious to me is that I have a different project where I do exactly this, and it builds and runs just fine. Could I possibly have done something to break my cargo project?