Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern crate serialize;
- use std::io::File;
- use serialize::json;
- use std::collections::TreeMap;
- fn main () {
- let fname = "/home/alex/src/bench/jsonParse/data/39m.json";
- let path = Path::new (fname);
- // Open the file path
- let display = path.display();
- let mut file = match File::open (&path) {
- Err(why) => fail!("{} {}",display ,why.desc),
- Ok(file) => file,
- };
- // Read the file contents into a heap allocated string
- let contents = match file.read_to_str() {
- Err(why) => fail!("{}", why.desc),
- Ok(text) => text,
- };
- // Parse the file contents into Rust valid JSON object
- let json = match json::from_str (contents.as_slice()) {
- Ok(json) => json,
- Err(err) => fail!("Invalid JSON. {}", err)
- };
- // println! ("{}", std::collections::TreeMap::map.len (json));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement