zoukankan      html  css  js  c++  java
  • 【GO】go json 操作

    golang json数据的转换

    1、json bytes 转结构体

        
    type CityWeather struct {
    	Data WatherDetail
    	Status int
    	Desc string
    }
    
    type WatherDetail struct {
    	Ysterday string
    	City string
    	Forecast []map[string]string
    	Ganmao string
    	Wendu string
    }
    
    
    func TestHttp3(t *testing.T){
    	queryWeatherURL := "http://wthrcdn.etouch.cn/weather_mini?city=杭州"
    
    	httpclient := &http.Client{}
    	resp, err := httpclient.Get(queryWeatherURL)
    	if err!=nil {
    		fmt.Println(err)
    		return
    	}
    	defer resp.Body.Close()
    	cityWeather :=  new(CityWeather)
    	_ = json.NewDecoder(resp.Body).Decode(cityWeather)
    
    	fmt.Println(cityWeather.Data.City)
    
    }
    
    
    “年轻时,我没受过多少系统教育,但什么书都读。读得最多的是诗,包括烂诗,我坚信烂诗早晚会让我邂逅好诗。” by. 马尔克斯
  • 相关阅读:
    CSP 训练赛0925
    赛道修建 NOIP 2018
    C
    B
    游戏得分 建立反图SPFA / bellman
    肥宅快乐树 换根+树形DP/dfs
    组合数例题
    龙珠雷达 双指针+DP
    面试-restful规范
    django-中间件
  • 原文地址:https://www.cnblogs.com/jzsg/p/10923514.html
Copyright © 2011-2022 走看看