- Published on
Go 将json字符串映射到map 存入couchDB时保持完整结构
- Authors
- Name
- JiGu
- @crypto20x
环境
在fabric链码中应用 

如果直接将字符串塞进去,就会变成这种结构,在couchDB中无法富查询
将要存入的json字符串marlshal到map
tmp := make(map[string]interface{})
str := "{\"UndergroundWaterlevel\":null,\"SupportInternal\":null,\"ColumnVertical\":null,\"BuildingTilt\":[{\"id\":\"\",\"monitoring_project\":\"\",\"section_code\":\"\",\"measuring_points_code\":\"\",\"this_change\":0,\"history_change\":0,\"rate_change\":0,\"monitoring_date\":\"0001-01-01T00:00:00Z\",\"sum_alarm_status\":\"\",\"change_rate_alarm_status\":\"\"}],\"Vote\":null}"
err = json.Unmarshal([]byte(str), &tmp)
// 再将map marshal成字节数组存入couchDB
b, err = json.Marshal(tmp)
stub.MockInvoke("123",[][]byte{[]byte("set"), []byte("map1"), b})