亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

基本的json>結構問題(使用'Go')

基本的json>結構問題(使用'Go')

Go
一只斗牛犬 2021-04-02 10:09:04
我正在使用Twitter的api,試圖從中獲取json數據http://search.twitter.com/trends/current.json看起來像:{"as_of":1268069036,"trends":{"2010-03-08 17:23:56":[{"name":"Happy Women's Day","query":"\"Happy Women's Day\" OR \"Women's Day\""},{"name":"#MusicMonday","query":"#MusicMonday"},{"name":"#MM","query":"#MM"},{"name":"Oscars","query":"Oscars OR #oscars"},{"name":"#nooffense","query":"#nooffense"},{"name":"Hurt Locker","query":"\"Hurt Locker\""},{"name":"Justin Bieber","query":"\"Justin Bieber\""},{"name":"Cmon","query":"Cmon"},{"name":"My World 2","query":"\"My World 2\""},{"name":"Sandra Bullock","query":"\"Sandra Bullock\""}]}}我的結構看起來像:type trend struct {   name  string   query string  }  type trends struct {   id string   arr_of_trends []trend  }  type Trending struct {   as_of  string   trends_obj trends  }然后將JSON解析為type的變量Trending。我是JSON的新手,所以我主要關心的是確保已正確設置數據結構以保存返回的json數據。我在“ Go”中為學校項目寫了這個。(這不是特定任務的一部分,而只是我正在演示有關該語言的演示內容)更新:根據PeterSO的評論,我要使用正則表達式。使用:Cur_Trends := new(Current)/* unmarshal the JSON into our structures *///find proper json time-nameaoUnixTime, _, _ := os.Time()// insert code to find and convert as_of Unix time to aoUnixTime    aoName := time.SecondsToUTC(aoUnixTime).Format(`"2006-01-02"`)    fmt.Printf("%s\n", aoName)    regexp_pattern := "/" + aoName + "/"    regex, _ := regexp.Compile(regexp_pattern);    cleaned_json := regex.ReplaceAllString(string(body2), "ntrends")    os.Stdout.WriteString(cleaned_json)不顯示任何更改。我指定的regexp錯誤嗎?看起來“開始”一次只允許一個正則表達式...更新:現在可以將日期/時間更改為“ ntrends”,但“取消編組”無效。我可以使用json.Decode將所有內容移入接口,但無法對其進行迭代...使用“ for ... range”給我奇怪的東西...
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 305 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號