pub fn to_array_iter<'de, I: JsonInput<'de>>(json: I) -> ArrayJsonIter<'de> ⓘ
Expand description
Traverse the JSON array text through a lazy iterator. The JSON parsing will doing when iterating.
The item of the iterator is Result<LazyValue>
.
§Errors
If the JSON is empty, not array or parse error, it will return Err and next()
will return
None
.
§Examples
use sonic_rs::JsonValueTrait;
for (i, ret) in to_array_iter(r#"[0, 1, 2, 3, 4, 5, 6]"#).enumerate() {
let lv = ret.unwrap(); // get lazyvalue
assert_eq!(i.to_string(), lv.as_raw_str()); // lv is not parsed
assert_eq!(i, lv.as_u64().unwrap() as usize);
}
for elem in to_array_iter(r#"[1, 2, 3, 4, 5, 6"#) {
// do something for each elem
// deal with errors when invalid json
if elem.is_err() {
assert!(elem
.unwrap_err()
.to_string()
.contains("Expected this character to be either a ',' or a ']'"));
}
}