Merge pull request #7 from brson/develop

Added detailed description on JSON recipe.
This commit is contained in:
Trent Spice 2017-02-25 13:26:21 -05:00 committed by GitHub
commit 4fa74d85f5

View file

@ -2,6 +2,11 @@
##JSON implementation in Rust:
The example below shows two simple ways to embed JSON in Rust.
The first method parses block JSON as a block using the parse method from the json crate. It then unwraps the parsed JSON.
The second method instantiates an object as JSON using the object macro. Key value relationships are easily set using `=>`.
After demonstrating two simple ways to write JSON, the `assert_eq!` macro ensures equivalence.
[![json][json-badge]][json]
@ -10,37 +15,29 @@
extern crate json;
fn main(){
let parsed = json::parse(r#"
let parsed_data = json::parse(r#"
{
"code": 200,
"success": true,
"payload": {
"features": [
"awesome",
"easyAPI",
"lowLearningCurve"
"userid": 103609,
"verified": true,
"access_privelages": [
"user",
"admin"
]
}
}
"#).unwrap();
let instantiated = object!{
"code" => 200,
"success" => true,
"payload" => object!{
"features" => array![
"awesome",
"easyAPI",
"lowLearningCurve"
let instantiated_data = object!{
"userid" => 103609,
"verified" => true,
"access_privelages" => array![
"user",
"admin"
]
}
};
assert_eq!(parsed, instantiated);
assert_eq!(parsed_data, instantiated_data);
}
```
# License