我正在嘗試編寫一個可以處理這樣的 json 響應(yīng)的結(jié)構(gòu)類型{"items":[{"name": "thing", "image_urls": { "50x100": [{ "url": "http://site.com/images/1/50x100.jpg", "width": 50, "height": 100 }, { "url": "http://site.com/images/2/50x100.jpg", "width": 50, "height": 100 }], "200x300": [{ "url": "http://site.com/images/1/200x300.jpg", "width": 200, "height": 300 }], "400x520": [{ "url": "http://site.com/images/1/400x520.jpg", "width": 400, "height": 520 }] }}由于鍵每次都不相同......不同的響應(yīng)可能有更多或更少的鍵,不同的鍵,并且正如您所看到的 50x100 返回特定大小的多個圖像,我如何創(chuàng)建與此匹配的結(jié)構(gòu)?我可以這樣做:type ImageURL struct { Url string Width, Height int}對于單個項目,以及特定鍵的列表。但是包含結(jié)構(gòu)的外觀如何?就像是:type Images struct { 50x100 []ImageURL ...}type Items struct { name string Image_Urls []Images}可能有用,但我無法列舉所有可能的圖像大小響應(yīng)。此外,最后的 Image_Urls 并沒有真正的列表。如果可能,我希望能夠?qū)⑵渲苯愚D(zhuǎn)儲到 json.Unmarshal 中。
- 1 回答
- 0 關(guān)注
- 230 瀏覽
添加回答
舉報
0/150
提交
取消