mirror of
https://github.com/rust-lang-nursery/rust-cookbook
synced 2024-11-22 03:23:05 +00:00
Merge branch 'master' of https://github.com/brson/rust-cookbook into contributing
This commit is contained in:
commit
368f8dcb56
1 changed files with 53 additions and 0 deletions
53
pages/json.md
Normal file
53
pages/json.md
Normal file
|
@ -0,0 +1,53 @@
|
|||
#JSON
|
||||
|
||||
##JSON implementation in Rust:
|
||||
|
||||
|
||||
[![json][json-badge]][json]
|
||||
|
||||
```rust
|
||||
#[macro_use]
|
||||
extern crate json;
|
||||
|
||||
fn main() {
|
||||
|
||||
let parsed = json::parse(r#"
|
||||
|
||||
{
|
||||
"code": 200,
|
||||
"success": true,
|
||||
"payload": {
|
||||
"features": [
|
||||
"awesome",
|
||||
"easyAPI",
|
||||
"lowLearningCurve"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
"#).unwrap();
|
||||
|
||||
let instantiated = object!{
|
||||
"code" => 200,
|
||||
"success" => true,
|
||||
"payload" => object!{
|
||||
"features" => array![
|
||||
"awesome",
|
||||
"easyAPI",
|
||||
"lowLearningCurve"
|
||||
]
|
||||
}
|
||||
};
|
||||
|
||||
assert_eq!(parsed, instantiated);
|
||||
|
||||
}
|
||||
```
|
||||
# License
|
||||
|
||||
MIT/Apache-2.0
|
||||
|
||||
<!-- Links -->
|
||||
[json-badge]: https://img.shields.io/crates/v/rustc-serialize.svg?label=json
|
||||
[json]: http://json.rs/doc/json/
|
||||
|
Loading…
Reference in a new issue