golang 读取 post json 信息

package main

import (
	"encoding/json"
	"fmt"
)

type fileinfo struct {
	FileName string // 首字母大写
}

type jsonfile struct {
	File []fileinfo // 与“file”对应,但是首字母需要大写
}

// 预定post过来数据
// 正常情况下 r.Boyd 中获取数据
// ioutil.ReadAll(r.Body) 获得信息 []byte

func main() {
	str := `{"file":[{"fileName":"text.exe"},{"fileName":"aria2.conf"}]}`
	var s jsonfile
	json.Unmarshal([]byte(str), &s)
	fmt.Println(s)
	fmt.Println(s.File[0]) // text.exe
}

猜你喜欢

转载自my.oschina.net/u/3529405/blog/1623405