Im trying to make the following work
use serde_json::Value;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let json = reqwest::get("https://www.bitmex.com/api/v1/instrument/indices")
.await?
.json::<serde_json::Value>()
.await?;
for key in json {
println!("{:?}", key["symbol"]);
}
Ok(())
}
which results in the following
--> src/main.rs:8:16
|
8 | for key in json {
| ^^^^ `Value` is not an iterator
|
= help: the trait `Iterator` is not implemented for `Value`
= note: required because of the requirements on the impl of `IntoIterator` for `Value`
I tried to implement it in the local source file serde_json-1.0.79/src/value/mod.rs
as
impl IntoIterator for Value {
type Item = Value;
type IntoIter = ValueIterator;
fn into_iter(self) -> Self::IntoIter {
ValueIterator {
slice: self.as_array().unwrap().iter(),
}
}
}
struct ValueIterator {
slice: std::slice::Iter<Value>,
}
impl Iterator for ValueIterator {
type Item = Value;
fn next(&mut self) -> Option<Self::Item> {
self.slice.next()
}
}
But the error remains, what can i change in the iterator implementation to make the code work as is?