Struct json::decoder::Decoder [] [src]

pub struct Decoder<I: Iterator> { /* fields omitted */ }

JSON decoder over char iterators.

Methods

impl<I: Iterator<Item = char>> Decoder<I>
[src]

Create decoder with default Config.

Have we exhausted the iterator?

Generic conversion from JSON to an instance of FromJson.

Decode into Json AST value.

Decode as generic Json but ignore the result.

Semantically this method is equivalent to Decoder::decode but potentially more efficient as it tries to avoid allocating intermediate values.

Decode a JSON string into the given Utf8Buffer.

If the actual string does not fit into the provided buffer and overflow_err is true, DecodeError::BufferOverflow is returned immediately. If overflow_err is false we continue decoding the string, but the buffer will only contain as much as fits into it.

Decode null (which is mapped to None) or some other JSON value (mapped to Some).

When parsing JSON arrays and objects this needs to be called in between to check if the array / object end has been reached. E.g.

use json::{Decoder, DecodeResult};

fn foo<I: Iterator<Item=char>>(d: &mut Decoder<I>) -> DecodeResult<Vec<u8>> {
    d.array()?;
    let mut v = Vec::new();
    while d.has_more()? {
        v.push(d.u8()?)
    }
    Ok(v)
}

Begin parsing a JSON array.

Before each element is parsed, Decoder::has_more needs to be queried.

Create a JSON array iterator to decode a homogenous array.

use json::Decoder;

let mut d = Decoder::default("[1,2,3,4]".chars());
let mut v: Vec<u8> = Vec::new();

for i in d.array_iter().unwrap() {
    v.push(i.unwrap())
}

Begin parsing a JSON object.

Before each key is parsed, Decoder::has_more needs to be queried.

Decode a JSON object key.

Decode a JSON object key into the given buffer.