我有由数组的子对象组成的json对象。如何在json中打印特定的子对象。这是我的代码
package main
import (
"encoding/json"
"fmt"
)
func main() {
//Simple Employee JSON which we will parse
empArray := `{"meta":[
{
"id": 1,
"name": "Mr. Boss",
"department": "",
"designation": "Director"
},
{
"id": 11,
"name": "Irshad",
"department": "IT",
"designation": "Product Manager"
},
{
"id": 12,
"name": "Pankaj",
"department": "IT",
"designation": "Team Lead"
}
]}`
// Declared an empty interface of type Array
var results []map[string]interface{}
// Unmarshal or Decode the JSON to the interface.
json.Unmarshal([]byte(empArray['meta']), &results)
fmt.Println(results)
}
我在执行操作时遇到错误。.>
./test.go:35:23: cannot convert empArray['\u0000'] (type byte) to type []byte ./test.go:35:33: invalid character literal (more than one character)
在
empArray
数组对象中,我想打印由雇员数组组成的meta
对象。请帮助我完成此任务。
我有由数组的子对象组成的json对象。如何在json中打印特定的子对象。这是我的代码包主要导入(“ encoding / json”“ fmt”)func main(){// ...
您快到了。解析整个文档,然后选择所需的部分。
您应该使用自定义结构: