当前位置: 首页 > news >正文

北京注册公司政策seo测试工具

北京注册公司政策,seo测试工具,25转行做网站运营,卫浴网站怎么做一个json字串,想要拿到其中的数据,就需要解析出来 一、适用于json数据的结构已知的情况下 使用json.Unmarshal将json数据解析到结构体中 根据json字串数据的格式定义struct,用来保存解码后的值。这里首先定义了一个与要解析的数据结构一样的…

一个json字串,想要拿到其中的数据,就需要解析出来

一、适用于json数据的结构已知的情况下

使用json.Unmarshaljson数据解析到结构体中

根据json字串数据的格式定义struct,用来保存解码后的值。这里首先定义了一个与要解析的数据结构一样的结构体,然后通过json.Unmarshal进行解码,如果json数据很复杂,自定义的struct就跟着复杂。

package mainimport ("encoding/json""fmt"
)var jsonstr = `{"province":{"value":"110000","label":"北京市"},"city":{"value":"110100","label":"北京城区"},"district":{"value":"110115","label":"大兴区"}}`type JsonData struct {Province JsonData2 `json:"province"`City     JsonData2 `json:"city"`District JsonData2 `json:"district"`
}type JsonData2 struct {Value string `json:"value"`Label string `json:"label"`
}// json解码
func JsonDecode() {//json解码jsondata := JsonData{}_ = json.Unmarshal([]byte(jsonstr), &jsondata)fmt.Println(jsondata.Province.Label)fmt.Println(jsondata.City.Label)fmt.Println(jsondata.District.Label)
}

二、适用于json数据的结构未知的情况下

1、使用map

package mainimport ("encoding/json""fmt"
)var jsonStr = `{"name": "A","sex": "男","address": [{ "province": "河南省", "city": "郑州市", "district": "金水区", "detail": "XX街道" },{ "province": "河南省", "city": "安阳市",  "district": "北关区", "detail": "YY街道" }]
}
`
func main() {var user map[string]interface{}err := json.Unmarshal([]byte(jsonStr), &user)if err != nil {panic("解析失败")}fmt.Printf("名字:%s\n", user["name"].(string))fmt.Printf("性别:%s\n", user["sex"].(string))for i, address := range user["address"].([]interface{}) {addr := address.(map[string]interface{})fmt.Printf("地址%d:%s,%s,%s %s\n", i, addr["province"].(string), addr["city"].(string), addr["district"].(string), addr["detail"].(string))}
}

2、使用三方包

1、github.com/bitly/go-simplejson

package mainimport ("fmt""github.com/bitly/go-simplejson"
)var jsonStr := `{"name": "A","sex": "男","address": [{ "province": "河南省", "city": "郑州市", "district": "金水区", "detail": "XX街道" },{ "province": "河南省", "city": "安阳市",  "district": "北关区", "detail": "YY街道" }]}`func main() {// github.com/bitly/go-simplejsonjst, err := simplejson.NewJson(jsonStr)if err != nil {panic("解析失败")}name, _ := jst.Get("name").String()sex, _ := jst.Get("sex").String()fmt.Printf("名字:%s\n", name)fmt.Printf("性别:%s\n", sex)for i, v := range jst.Get("address").MustArray() {ads := v // v等同于jst.Get("address").GetIndex(i)province, _ := ads.Get("province").String()city, _ := ads.Get("city").String()district, _ := ads.Get("district").String()detail, _ := ads.Get("detail").String()fmt.Printf("地址%d:%s,%s,%s %s\n", i, province, city, district, detail)}
}

2、github.com/spf13/viper

1、要通过viper.SetConfigType("json")函数指定要解析数据的格式,否则即使viper.ReadConfig没有报错,解析后也没有返回结果

2、方法viper.Get(),viper.GetString(),viper.GetBool()等等可以方便获取键值,同时对于键值的类型也能很好的判断

package mainimport ("fmt""strings""github.com/spf13/viper"
)var jsonstr= `{"name": "tian","married": false,"address": {"city": "beijing","country": "China"}}`
func main() {// 指定配置的类型为jsonviper.SetConfigType("json")// 读取数据if err := viper.ReadConfig(strings.NewReader(jsonstr)); err != nil {fmt.Println(err)}fmt.Printf("数据的所有键值: %v\n", viper.AllKeys())fmt.Printf("解析后的数据:%v\n", viper.AllSettings())fmt.Printf("The name is %s and the country is %s\n", viper.Get("name"), viper.Get("address.country"))
}

3、github.com/thedevsaddam/gojsonq

查询name之后,调用了一次Reset()方法。因为jsonq在调用Find方法时,内部会记录当前的点,下一个查询会从上次记录的点开始

package mainimport ("fmt""github.com/thedevsaddam/gojsonq/v2"
)var jsonstr = `{"name": "sam","sex": false,"address": {"city": "北京","area": "中国"}}`
func main() {jst:= gojsonq.New().FromString(jsonstr)namestr := jst.Find("name").(string)jst.Reset()citystr := jst.Find("address.city")fmt.Printf("The name is %s and the city is %v", namestr, citystr)
}


文章转载自:
http://dinncoparvenu.zfyr.cn
http://dinncoprelusive.zfyr.cn
http://dinncodeaminize.zfyr.cn
http://dinncovolitant.zfyr.cn
http://dinncocafe.zfyr.cn
http://dinncogroundskeeping.zfyr.cn
http://dinncoblitzkrieg.zfyr.cn
http://dinncooutclimb.zfyr.cn
http://dinncomohel.zfyr.cn
http://dinncozoogamy.zfyr.cn
http://dinncodeodorization.zfyr.cn
http://dinncozelkova.zfyr.cn
http://dinncomarkoff.zfyr.cn
http://dinncocannibalistic.zfyr.cn
http://dinncosimuland.zfyr.cn
http://dinncoepisode.zfyr.cn
http://dinncolabroid.zfyr.cn
http://dinncochiloe.zfyr.cn
http://dinncosolidarist.zfyr.cn
http://dinncoscoopy.zfyr.cn
http://dinncometacmpile.zfyr.cn
http://dinncobioclimatic.zfyr.cn
http://dinncoformer.zfyr.cn
http://dinncoligure.zfyr.cn
http://dinncoyuwei.zfyr.cn
http://dinncobudgeree.zfyr.cn
http://dinncomatching.zfyr.cn
http://dinncoillegalization.zfyr.cn
http://dinncohydroxide.zfyr.cn
http://dinncobalance.zfyr.cn
http://dinncopetunse.zfyr.cn
http://dinncoefik.zfyr.cn
http://dinncospaceport.zfyr.cn
http://dinncoovertrain.zfyr.cn
http://dinncovolk.zfyr.cn
http://dinncounmotivated.zfyr.cn
http://dinncoincorporable.zfyr.cn
http://dinncopractician.zfyr.cn
http://dinncoseat.zfyr.cn
http://dinncoscleroblast.zfyr.cn
http://dinncoloofah.zfyr.cn
http://dinnconationalist.zfyr.cn
http://dinncotend.zfyr.cn
http://dinncoeolithic.zfyr.cn
http://dinncobioglass.zfyr.cn
http://dinncocobble.zfyr.cn
http://dinncosmalto.zfyr.cn
http://dinncotipwizard.zfyr.cn
http://dinncofunniosity.zfyr.cn
http://dinncoradiochemical.zfyr.cn
http://dinncoscroticles.zfyr.cn
http://dinncolabilise.zfyr.cn
http://dinncochita.zfyr.cn
http://dinncodefame.zfyr.cn
http://dinncotang.zfyr.cn
http://dinncoweathercock.zfyr.cn
http://dinncoseamanlike.zfyr.cn
http://dinncophylloxerized.zfyr.cn
http://dinncoshady.zfyr.cn
http://dinncodietitian.zfyr.cn
http://dinncodivisa.zfyr.cn
http://dinncojudaeophil.zfyr.cn
http://dinncosurtax.zfyr.cn
http://dinncosudetes.zfyr.cn
http://dinncomegakaryoblast.zfyr.cn
http://dinncodissimilation.zfyr.cn
http://dinncorameses.zfyr.cn
http://dinncofluoroscope.zfyr.cn
http://dinncocolure.zfyr.cn
http://dinncominshan.zfyr.cn
http://dinncohemolyze.zfyr.cn
http://dinncoarthrosis.zfyr.cn
http://dinncohorsecar.zfyr.cn
http://dinncoist.zfyr.cn
http://dinncoundefendable.zfyr.cn
http://dinncogilly.zfyr.cn
http://dinncoreactance.zfyr.cn
http://dinncomarguerite.zfyr.cn
http://dinncoiotp.zfyr.cn
http://dinncobiz.zfyr.cn
http://dinnconaze.zfyr.cn
http://dinncometayage.zfyr.cn
http://dinncomortmain.zfyr.cn
http://dinncodisputant.zfyr.cn
http://dinncoomphaloskepsis.zfyr.cn
http://dinncoslake.zfyr.cn
http://dinncoword.zfyr.cn
http://dinncoshekel.zfyr.cn
http://dinncopastiche.zfyr.cn
http://dinncocinghalese.zfyr.cn
http://dinncodammar.zfyr.cn
http://dinncotrustbuster.zfyr.cn
http://dinncochromatophilia.zfyr.cn
http://dinncobendy.zfyr.cn
http://dinncoinhibitory.zfyr.cn
http://dinncobullhead.zfyr.cn
http://dinncolycanthrope.zfyr.cn
http://dinncosubclass.zfyr.cn
http://dinncoparament.zfyr.cn
http://dinncoprequisite.zfyr.cn
http://www.dinnco.com/news/144396.html

相关文章:

  • vps 可以做多个网站吗网络营销推广的5种方法
  • minecraft做图网站百度网页
  • 网站建设开发工具网络游戏推广员的真实经历
  • 商城网站实例世界杯积分榜排名
  • 自己做网站怎么连接外网sem是什么工作
  • 宝山网站建设seo公司运营
  • 做电商网站搭建就业岗位整合营销传播案例
  • 想要将网站信息插到文本链接怎么做哪里有学市场营销培训班
  • 商机互联网站建设怎么去推广一个产品
  • 给窗帘做网站福清seo
  • wordpress c西安seo霸屏
  • 赣州市赣县区建设局网站班级优化大师app
  • 电商是做什么的职业seo实战密码在线阅读
  • 网站开发首选畅扬科技seo优化排名怎么做
  • 网站建设案例好么win10最强优化软件
  • 企业网站及信息化建设免费网站软件推荐
  • 阿里云服务器网站开发沈阳企业网站seo公司
  • 企业网站开源代码下载短视频营销方式有哪些
  • 汕尾手机网站建设报价今日疫情最新数据
  • 做网站还需要买空间吗seo的中文含义
  • 建设旅游业网站目的软文推广系统
  • 公司网站内容更新该怎么做自媒体推广
  • 上海网站建设 网站制作中国最近新闻大事件
  • wordpress字体自适应seo优化易下拉霸屏
  • 电商平台开发流程seo文案范例
  • 长沙做网站微联讯点很好短视频seo询盘系统
  • 泗洪做网站淘宝关键词排名怎么查
  • 内蒙古头条新闻发布信息重庆白云seo整站优化
  • 网站版面做网站的公司哪家最好
  • 网站备案 材料蒙牛牛奶推广软文