2 回答
TA贡献1824条经验 获得超8个赞
到目前为止,我已经采用了这种方法,但我不确定它是否是最好的。
var out bytes.Buffer
err := json.Indent(&out, jsonData.Bytes(), "", " ")
if err != nil {
log.Fatal(err)
}
outStr := out.String()
slice := strings.Split(outStr,"\n")
TA贡献1900条经验 获得超5个赞
如果我理解正确,您想比较确切字段的匹配。所以你可以尝试使用map[string]string{}
这是一个例子
var jsonMap = map[string]string{}
var json = []byte
json = // get your json bytes here
json.Unmarshal(json, &jsonMap)
// Access your field's value
fmt.Println(jsonMap["key"])
// If you want slice, convert values from map to string slice
slice := mapToSlice(jsonMap)
func mapToSlice(jsonMap map[string]string) []string {
slice := make([]string)
for _, value := range jsonMap {
slice = append(slice, value)
}
return slice
}
- 2 回答
- 0 关注
- 172 浏览
添加回答
举报
