为了账号安全,请及时绑定邮箱和手机立即绑定

golang - 解析复杂json

golang - 解析复杂json

慕哥9229398 2019-03-29 22:10:21
代码在这里http://play.golang.org/p/l1__b2FOsv//Clickhereandstarttyping.packagemainimport"fmt"import"encoding/json"typeMxRecordsstruct{valuestringttlintpriorityinthostNamestring}typeDatastruct{mxRecords[]MxRecords}typeResponsestruct{Statusstring`json:"status"`DataData`json:"data"`}typeapiRstruct{ResponseResponse`json:"response"`}funcmain(){body:=`{"response":{"status":"SUCCESS","data":{"mxRecords":[{"value":"us2.mx3.mailhostbox.com.","ttl":1,"priority":100,"hostName":"@"},{"value":"us2.mx1.mailhostbox.com.","ttl":1,"priority":100,"hostName":"@"},{"value":"us2.mx2.mailhostbox.com.","ttl":1,"priority":100,"hostName":"@"}],"cnameRecords":[{"aliasHost":"pop.a.co.uk.","canonicalHost":"us2.pop.mailhostbox.com."},{"aliasHost":"webmail.a.co.uk.","canonicalHost":"us2.webmail.mailhostbox.com."},{"aliasHost":"smtp.a.co.uk.","canonicalHost":"us2.smtp.mailhostbox.com."},{"aliasHost":"imap.a.co.uk.","canonicalHost":"us2.imap.mailhostbox.com."}],"dkimTxtRecord":{"domainname":"20a19._domainkey.a.co.uk","value":"\"v=DKIM1;g=*;k=rsa;p=DkfbhO8Oyy0E1WyUWwIDAQAB\"","ttl":1},"spfTxtRecord":{"domainname":"a.co.uk","value":"\"v=spf1redirect=_spf.mailhostbox.com\"","ttl":1},"loginUrl":"us2.cp.mailhostbox.com"}}}`varrapiRerr:=json.Unmarshal([]byte(body),&r)iferr!=nil{fmt.Printf("errwas%v",err)}fmt.Println(r)}解析出来data为空,这是为何?不用interface该如何解析
查看完整描述

2 回答

  • 2 回答
  • 0 关注
  • 1064 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信