Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the json serializations of special characters

Shulou Source: shulou.com Published: 2022-06-03 19:12:47 09月17日 Update

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":"

Tags: Result sequence output character article escape special more first come good practical small obvious same content string byte technology document article Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Shulou Technology Shulou Information MySQL Linux