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

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

可以使用恐慌/恢復(fù)作為測試成功類型斷言的手段嗎?

可以使用恐慌/恢復(fù)作為測試成功類型斷言的手段嗎?

Go
慕田峪4524236 2021-09-10 10:58:01
我一直在研究一種嘗試解析嵌套 JSON 響應(yīng)而不將信息映射到預(yù)定義結(jié)構(gòu)的方法。使用空白界面,它返回為:map[name:My Folder parentId:1 created:2014-10-09T16:32:07+0000 deleted:false description:Sync Dir id:3 links:[map[rel:self entity:folder href:https://web .domain.org/rest/folders/3 id:3] map[href:https://web.domain.org/rest/folders/1 id:1 rel:parent entity:folder] map[entity:user href: https://web.domain.org/rest/users/1 id:1 rel:creator]] 修改時間:2014-12-18T18:07:01+0000 固定鏈接:https://web.domain.org/w/ SpJYGQkv syncable:true type:d userId:1]所以我使用以下內(nèi)容來瀏覽這些信息:func NFind(input interface{}, refs...interface{}) (output interface{}) {    defer func() {if r := recover(); r != nil { output = nil }}()    for _, ref := range refs {        switch cur := ref.(type) {            case string:                output = input.(map[string]interface{})[cur]            case int:                output = input.([]interface{})[cur]        }     }    return output}func NMap(input interface{}) (output map[string]interface{}) {    defer func() {if r := recover(); r != nil {}}()    if input == nil { return nil }    return input.(map[string]interface{})}func NArray(input interface{}) (output []interface{}) {    defer func() {if r := recover(); r != nil {}}()    if input == nil { return nil }    return input.([]interface{})}func NString(input interface{}) (output string) {    defer func() {if r := recover(); r != nil {}}()    if input == nil { return "" }    return input.(string)}func NFloat64(input interface{}) (output float64) {    defer func() {if r := recover(); r != nil {}}()    if input == nil { return 0 }    return input.(float64)} 這是從 JSON 字符串解析信息的可接受方式,還是有更可取的方法?以下是使用上述內(nèi)容解析出我當(dāng)前使用的正確信息的示例:func mapCache(input map[string]interface{}, valType string) {    fmt.Println(input)    var (        name string        href string        rel string        links []interface{}        myMap map[string]interface{}    )
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 166 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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