pub struct JSONDocument {
pub value: Option<JSONValue>,
}Fields§
§value: Option<JSONValue>Implementations§
Source§impl JSONDocument
impl JSONDocument
Sourcepub fn new() -> JSONDocument
pub fn new() -> JSONDocument
Examples found in repository?
examples/print.rs (line 13)
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(v) => println!("print: {}", v.to_string()),
16 Err(err) => print!("err: {}", err),
17 }
18}More examples
examples/parse.rs (line 13)
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}Sourcepub fn parse_string(&mut self, content: String) -> Result<JSONValue, JSONError>
pub fn parse_string(&mut self, content: String) -> Result<JSONValue, JSONError>
Examples found in repository?
examples/print.rs (line 14)
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(v) => println!("print: {}", v.to_string()),
16 Err(err) => print!("err: {}", err),
17 }
18}More examples
examples/parse.rs (line 14)
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 parse_file(&mut self, file: File) -> Result<JSONValue, JSONError>
pub fn to_string(&mut self) -> Result<String, JSONError>
pub fn pretify(&mut self) -> String
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JSONDocument
impl RefUnwindSafe for JSONDocument
impl Send for JSONDocument
impl Sync for JSONDocument
impl Unpin for JSONDocument
impl UnsafeUnpin for JSONDocument
impl UnwindSafe for JSONDocument
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