代码在这里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该如何解析
添加回答
举报
0/150
提交
取消