第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

如何將接口內(nèi)的值轉換為golang中的地圖?

如何將接口內(nèi)的值轉換為golang中的地圖?

Go
料青山看我應如是 2022-06-27 15:04:23
我是 GO 的新手。我的目標是獲取 item.Data 中的數(shù)據(jù)并將它們放入地圖中,以便我可以將它們作為鍵值對進行訪問。據(jù)我了解,空接口與 Typescript 中的任何類型相同。你能分享一下如何在goLang中做到這一點嗎?type SearchLogsResponse struct {    // The underlying http response    RawResponse *http.Response    // A list of SearchResponse instances    SearchResponse `presentIn:"body"`    // For list pagination. When this header appears in the response, additional pages    // of results remain. For important details about how pagination works, see    // List Pagination (https://docs.cloud.oracle.com/iaas/Content/API/Concepts/usingapi.htm#nine).    OpcNextPage *string `presentIn:"header" name:"opc-next-page"`    // Unique Oracle-assigned identifier for the request. If you need to contact    // Oracle about a particular request, please provide the request ID.    OpcRequestId *string `presentIn:"header" name:"opc-request-id"`}// SearchResult 日志搜索結果條目type SearchResult struct {    // JSON blob containing the search entry with projected fields.    Data *interface{} `mandatory:"true" json:"data"`}// SearchResponse Search response object.type SearchResponse struct {    Summary *SearchResultSummary `mandatory:"true" json:"summary"`    // List of search results    Results []SearchResult `mandatory:"false" json:"results"`    // List of log field schema information.    Fields []FieldInfo `mandatory:"false" json:"fields"`}res, err1 := o.loggingSearchClient.SearchLogs(ctx, request)    for _, item := range res.Results {            //TODO create a map string [string]            // Put key value pairs from item into the above map}PS:item.Data 里面的數(shù)據(jù)是一個鍵值對的列表,其中每個鍵可以包含另一個接口內(nèi)的數(shù)據(jù),其值是一個字符串
查看完整描述

1 回答

?
動漫人物

TA貢獻1815條經(jīng)驗 獲得超10個贊

第一:不要使用*interface{},而是使用interface{}。


您可以使用類型斷言來測試底層類型,Data如果它是 a 則遞歸下降map[string]interface{}:


(您提到這是 SDK 的一部分,無法更改,因此解決方法是取消引用接口)


if m, ok:=(*item.Data).(map[string]interface{}); ok {

   // m is a map[string]interface{}

   etag:=m["data.eTag"]

   // etag is an interface{}

   if str, ok:=etag.(string); ok {

      // str contains the string value

   }

}


查看完整回答
反對 回復 2022-06-27
  • 1 回答
  • 0 關注
  • 126 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號