SHARE
TWEET

Untitled

a guest Aug 23rd, 2019 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern crate serde;
  2. extern crate serde_json;
  3. extern crate serde_derive;
  4.  
  5. use serde_json::{Result};
  6. use serde::{Deserialize};
  7.  
  8. #[derive(Deserialize, Debug)]
  9. struct Info {
  10.   info: Vec<ItemInfo>
  11. }
  12.  
  13. #[derive(Deserialize, Debug)]
  14. struct ItemInfo
  15. {
  16.   a: String,
  17.   b: String,
  18.   c: String,
  19.   d: String
  20. }
  21.  
  22. fn main() -> Result<()>
  23. {
  24.     let data = r#"
  25. {
  26.     "info": [
  27.         {
  28.             "a": "-0.000100000000000000000000000000",
  29.             "b": "800000",
  30.             "c": "0.010000000000000000000000000000",
  31.             "d": "10000.000000000000000000000000000000"
  32.         }
  33.     ]
  34. }"#;
  35.  
  36.     // Parse the string of data into serde_json::Value.
  37.     let v: Info = serde_json::from_string(data)?;
  38.  
  39.     // Access parts of the data by indexing with square brackets.
  40.     println!("a {}", v.info[0].a);
  41.  
  42.     Ok(())
  43. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top