Skip to content

Instantly share code, notes, and snippets.

@selfup
Created May 22, 2016 23:13
Show Gist options
  • Save selfup/bb532c7bd9f36f7d2dfa4c1e457c1b3e to your computer and use it in GitHub Desktop.
Save selfup/bb532c7bd9f36f7d2dfa4c1e457c1b3e to your computer and use it in GitHub Desktop.
extern crate rustc_serialize;
use rustc_serialize::json::{self, ToJson, Json};
use std::collections::HashMap;
#[no_mangle]
pub extern fn read_json(ro: &'static str) -> String {
let roo = ro.to_string();
let json_for_rust: HashMap<String, i32> = json::decode(&roo).unwrap();
let encoded = json::encode(&json_for_rust).unwrap();
encoded
}
#[test]
fn it_reads_the_json() {
let string = "{\"wow\":\"6\"}";
let ro = string;
assert_eq!("{\"wow\":6}", read_object(ro));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment