golang 调用第三方api 实例(返回json并解析)

  • Post author:
  • Post category:golang




解析json 并接收

package main
import (
"encoding/json"
"fmt"
"os"
)
type ConfigStruct struct {
   
Host              string   `json:"host"`
Port              int      `json:"port"`
AnalyticsFile     string   `json:"analytics_file"`
StaticFileVersion int      `json:"static_file_version"`
StaticDir         string   `json:"static_dir"`
TemplatesDir      string   `json:"templates_dir"`
SerTcpSocketHost  string   `json:"serTcpSocketHost"`
SerTcpSocketPort  int      `json:"serTcpSocketPort"`
Fruits            []string `json:"fruits"`
}
type Other struct {
   
SerTcpSocketHost string   `json:"serTcpSocketHost"`
SerTcpSocketPort int      `json:"serTcpSocketPort"`
Fruits           []string `json:"fruits"`
}
type Object []interface{
   }
func main() {
   
jsonStr := `{"host": "http://localhost:9090","port": 9090,"analytics_file": "","static_file_version": 1,"static_dir": "E:/Project/goTest/src/","templates_dir": "E:/Project/goTest/src/templates/","serTcpSocketHost": ":12340","serTcpSocketPort": 12340,"fruits": ["apple", "peach"]}`



版权声明:本文为weixin_41635460原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。