我正在使用 API 接收來自某個組織的所有招聘廣告,我收到的 JSON 數(shù)據(jù)非常大,我想在 Go 中使用這些數(shù)據(jù),但是我在解組到結(jié)構(gòu)時遇到了問題,因此我可以進一步使用它。這可能是一個非常簡單的解決方案,對我來說是盲目的,因為我這個問題引起了一些頭痛。代碼中的 API 密鑰是公開的,因此與 Stackoverflow 共享它沒有問題。代碼:package mainimport ( "encoding/json" "fmt" "io/ioutil" "log" "net/http")type JsonData struct { Content JsonContent `json:"content"` TotalElements int `json:"totalElements"` PageNumber int `json:"pageNumber"` PageSize int `json:"pageSize"` TotalPages int `json:"totalPages"` First bool `json:"first"` Last bool `json:"last"` Sort string `json:"sort"`}type JsonContent struct { Uuid string `json:"uuid"` Published string `json:"published"` Expires string `json:"expires"` Updated string `json:"updated"` WorkLoc WorkLocations `json:"workLocations"` Title string `json:"title"` Description string `json:"description"` SourceUrl string `json:"sourceurl"` Source string `json:"source"` ApplicationDue string `json:"applicationDue"` OccupationCat OccupationCategories `json:"occupationCategories"` JobTitle string `json:"jobtitle"` Link string `json:"link"` Employ Employer `json:"employer"` EngagementType string `json:"engagementtype"` Extent string `json:"extent"` StartTime string `json:"starttime"` PositionCount interface{} `json:"positioncount"` Sector string `json:"sector"`}type WorkLocations struct { Country string `json:"country"` Address string `json:"address"` City string `json:"city"` PostalCode string `json:"postalCode"` County string `json:"county"` Municipal string `json:"municipal"`}type OccupationCategories struct { Level1 string `json:"level1"` Level2 string `json:"level2"`}type Employer struct { Name string `json:"name"` Orgnr string `json:"orgnr"` Description string `json:"description"` Homepage interface{} `json:"homepage"`}
1 回答

忽然笑
TA貢獻1806條經(jīng)驗 獲得超5個贊
解決方案已經(jīng)被“zerkms”、“tclass”這兩個可愛的人找到了。
您聲稱 Content JsonContentjson:"content"
是 JsonContent,而它是它們的數(shù)組,因此 []JsonContent
正如您在示例 json 中看到的,內(nèi)容字段實際上是一個數(shù)組。在你的 go 結(jié)構(gòu)中它不是。您必須將結(jié)構(gòu)更改為 Content []JsonContent json:"content"
非常感謝你們!
- 1 回答
- 0 關(guān)注
- 204 瀏覽
添加回答
舉報
0/150
提交
取消