pub enum JSONValue {
Null,
Boolean(bool),
Number(f64),
String(String),
Object(HashMap<String, JSONValue>),
Array(Vec<JSONValue>),
}Variants§
Null
Boolean(bool)
Number(f64)
String(String)
Object(HashMap<String, JSONValue>)
Array(Vec<JSONValue>)
Implementations§
Source§impl JSONValue
impl JSONValue
pub fn as_str(&self) -> String
pub fn as_i64(&self) -> i64
pub fn as_f64(&self) -> f64
pub fn as_bool(&self) -> bool
pub fn as_array(&self) -> Vec<JSONValue>
pub fn as_map(&self) -> HashMap<String, JSONValue>
Sourcepub fn get(&self, k: &str) -> Option<JSONValue>
pub fn get(&self, k: &str) -> Option<JSONValue>
Examples found in repository?
examples/parse.rs (line 16)
3fn main() {
4 let data = r#"{
5 "name": "John Doe",
6 "age": 43,
7 "props": { "weight": 76, "height": 2.3 },
8 "primes": [ 11, 13, 17, 19, 23 ],
9 "colors": [ "red", "blue" ]
10 }"#;
11
12 let json = String::from(data);
13 let mut doc = JSONDocument::new();
14 match doc.parse_string(json) {
15 Ok(ref mut v) => {
16 println!("name: {}", v.get("name").unwrap()); // John Doe
17 println!("age: {}", v.get("age").unwrap()); // 43
18 match v {
19 JSONValue::Object(hm) => {
20 *hm.get_mut("age").unwrap() = JSONValue::Number(45f64);
21 }
22 _ => {}
23 };
24 println!("age: {}", v.get("age").unwrap()); // 45
25 }
26 Err(err) => print!("err: {}", err),
27 }
28}pub fn exists() -> bool
pub fn is_number(&self) -> bool
pub fn is_string(&self) -> bool
pub fn is_bool(&self) -> bool
pub fn is_object(&self) -> bool
pub fn is_array(&self) -> bool
pub fn is_null(&self) -> bool
Trait Implementations§
impl StructuralPartialEq for JSONValue
Auto Trait Implementations§
impl Freeze for JSONValue
impl RefUnwindSafe for JSONValue
impl Send for JSONValue
impl Sync for JSONValue
impl Unpin for JSONValue
impl UnsafeUnpin for JSONValue
impl UnwindSafe for JSONValue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more