What are the json serializations of special characters
This article will explain in detail what json serialization of special characters has, Xiaobian thinks it is quite practical, so share it with you as a reference, I hope you can gain something after reading this article.
Let's take a look at a golang.
package mainimport ( "encoding/json" "fmt")func main() { data := map[string]string{ "str0": "Hello, world", "str1": "", "str3": "&", } jsonStr, _ := json.Marshal(data) fmt.Println(string(jsonStr))}
output result
{"str0":"Hello, world","str1":"\u003c","str2":"\u003e","str3":"\u0026"}
Let's start with rust.
extern crate rustc_serialize;use rustc_serialize::json;use std::collections::HashMap;fn main(){ let mut data = HashMap::new(); data.insert("str0","Hello, world"); data.insert("str1",""); data.insert("str3","&"); println! ("{}", json::encode(&data).unwrap());}}
results
{"str0":"Hello, world","str2":">","str1":"