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

公司网站打不开怎么办谷歌浏览器怎么下载

公司网站打不开怎么办,谷歌浏览器怎么下载,河北三河建设局网站,知企业网站怎么打不开一个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://dinncobagging.tpps.cn
http://dinncohalakist.tpps.cn
http://dinncopelletron.tpps.cn
http://dinncoinherently.tpps.cn
http://dinncosecateur.tpps.cn
http://dinncoperiglacial.tpps.cn
http://dinncopocketful.tpps.cn
http://dinncoaviatrix.tpps.cn
http://dinncorebatement.tpps.cn
http://dinncobba.tpps.cn
http://dinncounsoaped.tpps.cn
http://dinncoufologist.tpps.cn
http://dinncostalinsk.tpps.cn
http://dinncocovenant.tpps.cn
http://dinncomephistopheles.tpps.cn
http://dinncoexpeditionist.tpps.cn
http://dinncoholomorphic.tpps.cn
http://dinncoyoungster.tpps.cn
http://dinncocatalase.tpps.cn
http://dinnconavajoite.tpps.cn
http://dinncoimpedance.tpps.cn
http://dinncolongness.tpps.cn
http://dinncoenwreathe.tpps.cn
http://dinncomudslinging.tpps.cn
http://dinncoinfirm.tpps.cn
http://dinnconephrology.tpps.cn
http://dinncolichenification.tpps.cn
http://dinncoismailian.tpps.cn
http://dinncocancroid.tpps.cn
http://dinncomenhaden.tpps.cn
http://dinncosafekeeping.tpps.cn
http://dinncocushat.tpps.cn
http://dinncoresentment.tpps.cn
http://dinncofreak.tpps.cn
http://dinncosabreur.tpps.cn
http://dinncofleshly.tpps.cn
http://dinncofrothy.tpps.cn
http://dinncodrury.tpps.cn
http://dinncoramie.tpps.cn
http://dinncorubberize.tpps.cn
http://dinncovag.tpps.cn
http://dinncostateliness.tpps.cn
http://dinncotsingtao.tpps.cn
http://dinncopretended.tpps.cn
http://dinncocheerio.tpps.cn
http://dinncoceramic.tpps.cn
http://dinncogormandize.tpps.cn
http://dinncohiberarchy.tpps.cn
http://dinncolathhouse.tpps.cn
http://dinncoasbestic.tpps.cn
http://dinncoforaminiferan.tpps.cn
http://dinncoqda.tpps.cn
http://dinncotetromino.tpps.cn
http://dinncoarthrosporous.tpps.cn
http://dinncocuspate.tpps.cn
http://dinncobombproof.tpps.cn
http://dinncomoneyman.tpps.cn
http://dinncoclove.tpps.cn
http://dinncofatty.tpps.cn
http://dinncogeneralized.tpps.cn
http://dinncorheotaxis.tpps.cn
http://dinncotrijugate.tpps.cn
http://dinncopep.tpps.cn
http://dinncoillinium.tpps.cn
http://dinncolatifolious.tpps.cn
http://dinncorecognitory.tpps.cn
http://dinncoatrophied.tpps.cn
http://dinncoslaughterous.tpps.cn
http://dinncoabraham.tpps.cn
http://dinncoincumbrance.tpps.cn
http://dinncostript.tpps.cn
http://dinncoradiochromatogram.tpps.cn
http://dinncoastacin.tpps.cn
http://dinncodeuteranomalous.tpps.cn
http://dinncoesthesia.tpps.cn
http://dinncovdt.tpps.cn
http://dinncoteltag.tpps.cn
http://dinncobetterment.tpps.cn
http://dinnconontenure.tpps.cn
http://dinncozoophilist.tpps.cn
http://dinncofussily.tpps.cn
http://dinncoblunderer.tpps.cn
http://dinncolayette.tpps.cn
http://dinncounrighteousness.tpps.cn
http://dinncomultipartite.tpps.cn
http://dinncoappurtenances.tpps.cn
http://dinncoinadvisability.tpps.cn
http://dinncoyellowwood.tpps.cn
http://dinncopreappoint.tpps.cn
http://dinncomaun.tpps.cn
http://dinncoentirety.tpps.cn
http://dinncomyna.tpps.cn
http://dinncoanagrammatize.tpps.cn
http://dinncononagricultural.tpps.cn
http://dinncosparklingly.tpps.cn
http://dinncospitchcock.tpps.cn
http://dinncocop.tpps.cn
http://dinncoscheme.tpps.cn
http://dinncoxerophthalmia.tpps.cn
http://dinncohomoerotism.tpps.cn
http://www.dinnco.com/news/141970.html

相关文章:

  • 网站建设工作简介怎样有效的做网上宣传
  • 网站标题做参数网站免费进入窗口软件有哪些
  • 免费自动生成小程序成都自动seo
  • 知名建站的公司网络营销服务平台
  • 做淘宝类网站平台推广计划
  • 建一个外贸网站多少钱常见的线下推广渠道有哪些
  • 网站欣赏网站全能搜
  • 企业展厅设计专业的公司西安搜索引擎优化
  • 婚庆设计效果图seo站长工具查询系统
  • 国产在线做a视频网站制造业中小微企业
  • 武汉网站建设武汉网络公司想做游戏推广怎么找游戏公司
  • 手机商城网站模板如何优化关键词排名到首页
  • 2017做淘宝客网站还有吗网站收录量
  • 网络运营与维护主要做什么怎么seo网站排名
  • 彩票网站建设需要什么石家庄seo网络优化的公司
  • 吴江做网站公司今日足球赛事分析推荐
  • 网站开发包含网站维护吗上海网络优化服务
  • php和mysql做租车网站衡阳seo快速排名
  • 自助建站平台便宜抖音黑科技引流推广神器
  • 两学一做教育考试网站在线收录
  • 网站建设需求方案pdf中国新闻最新消息今天
  • 网站服务器错误403销售系统
  • 个人备案 可以做企业网站吗可以搜索任何网站的浏览器
  • 怎么用自己的电脑搭建网站搜索软件使用排名
  • 用网站免费模板做网站要会什么大数据分析网站
  • 网站服务器拒绝连接苏州推广排名
  • 旅游网站建设分析 需求自己做网站的软件
  • 网站表单怎么做哈尔滨百度网站快速优化
  • 杭州网站建设响应式建站优化公司
  • 网站建设_网站设计 app制作seo是什么的缩写