use errors::Result;
use serde_json::{self, Value};
pub fn chat_to_str(chat: &str) -> Result<String> {
let mut ret = String::new();
let data = serde_json::from_str(chat)?;
chat_to_str_parse_json(&data, &mut ret);
Ok(ret)
}
fn chat_to_str_parse_json(json: &Value, ret: &mut String) {
match json.get("text") {
Some(&Value::String(ref x)) => ret.push_str(x),
_ => (),
}
match json.get("extra") {
Some(&Value::Array(ref x)) => {
for object in x {
chat_to_str_parse_json(object, ret);
}
},
Some(ref x) => chat_to_str_parse_json(x, ret),
None => (),
}
}