最近处理json数据,json中数据下划线形式,找了半天没有找到能把下划线处理成驼峰式的代码~ 自己动手!
功能:把例如 "the_red_apple":"very_nice" 转化为 "TheRedApple":"very_nice" 这种。
代码:https://github.com/SkyingzZ/camel_json_keys
//下划线写法转为驼峰写法 like "sample_test_name_balabala" to "SampleTestNameBalabala"
func CamelName(name string) string {
name = strings.Replace(name, "_", " ", -1)
name = strings.Title(name)
return strings.Replace(name, " ", "", -1)
}
func CamelJsonKey(json_data []byte) []byte{
str := string(json_data)
var is_quot_first bool = true //在双引号中为 false | the value in the double quotes is false
var first_index int = 0 //左引号的索引 | the left quote index
var second_index int = 0 //右引号的索引 | the right quote index
var res_str string
var the_key_index int
fo