我有包含数组子对象的 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包含员工数组的对象。请帮我完成这个。
德玛西亚99
慕尼黑8549860
慕盖茨4494581
随时随地看视频慕课网APP
相关分类