草庐IT

音频编解码

全部标签

go - 我如何解码 Dynamic Viper 或 JSON 键作为结构字段的一部分

当JSON不是“所需”格式时,我发现GOLANG中的编码(marshal)处理和解封处理非常困惑。例如,在一个JSON配置文件(我正在尝试将其与Viper一起使用)中,我有一个如下所示的配置文件:{"things":{"123abc":{"key1":"anything","key2":"more"},"456xyz":{"key1":"anything2","key2":"more2"},"blah":{"key1":"anything3","key2":"more3"}}}其中“事物”可能是另一个对象中的对象n层以下我有一个结构:typeThingstruct{Namestring

json - 有条件地将 JSON 解码为结构的简洁方法

我正在向JSONAPI发送请求,它要么返回错误...{"error":{"code":404,"message":"Documentnotfound.","status":"NOT_FOUND"}}或数据。{"name":"projectname","fields":{"userId":{"stringValue":"erw9384rjidfge"}},"createTime":"2018-06-28T00:52:25.638791Z","updateTime":"2018-06-28T00:52:25.638791Z"}下面是相应的结构体typeHttpErrorstruct{Cod

go - 我如何在 Go 中对接口(interface) slice 进行 json 解码?

我正在将json.Decode()'ing(请原谅我的速记)从api到大型结构的json响应。在该结构中有一些属于[]interface{}类型的类型。我不知道如何从那些特殊的嵌套结构中提取任何数据。我曾尝试使用caseswitch类型检查解决方案,但仍然空手而归。有人可以分享他们在类似案例中的经验或为我指明正确的方向吗?m:=new(largestruct)iferr:=json.NewDecoder(resp.Body).Decode(&m);err!=nil{returnerr}接口(interface)的结构字段是:Strings[]interface{}`json:"stri

go - 解码在根级别没有键的元组

我正在尝试使用golang,并认为从restapi解析一些json是一个很好的用例。它看起来就像定义一个结构并将api响应解码到其中一样简单。当然,我正在使用的api响应并不是一个很好的选择。我正在玩craigslistjsonsearch-响应是2个对象的数组。第一个对象是结果数组,第二个对象是misc。元数据。[[{"Ask":6000,"CategoryID":145,"ImageThumb":"https:\/\/images.craigslist.org\/01212_dZ9PfxSmjEH_50x50c.jpg","Latitude":39.591784,"Longitud

go - 在解码字段的 JSON 内容时打印结构字段标签?

在Go中,是否可以在我将JSON内容解码到结构字段时从结构字段中获取标签?这是我失败的尝试:packagemainimport("log""encoding/json")typePersonstruct{ProfileNameAltField`json:"profile_name"`}typeAltFieldstruct{Valstring}func(af*AltField)UnmarshalJSON(b[]byte)error{log.Println("Showtags")//log.Println(af.Tag)//Iwanttosee`json:"profile_name"`if

php - 迭代从 PHP 序列化格式解码的 map

我如何以map格式读取golang中的条件反序列化数据?[map[19:map[conditions:map[0:map[operator:==value:AMW-1900-50SLE-ROOMis_value_processed:falsetype:feedexport/rule_condition_productattribute:sku]1:map[type:feedexport/rule_condition_productattribute:skuoperator:==value:ASL-B654-77-74-98-ROOMis_value_processed:false]2:

json - 在 Go 中解码复杂的 json

所以我试图通过ping和端点来获取应用程序的分析。我发出成功的GET请求(那里没有错误)但我无法解码JSON我需要将下面的json解码成结构体{"noResultSearches":{"results":[{"count":1,"key":"\"note9\""},{"count":1,"key":"nokia"}]},"popularSearches":{"results":[{"count":4,"key":"6"},{"count":2,"key":"\"note9\""},{"count":1,"key":"nokia"}]},"searchVolume":{"results"

json - 为什么不能将此数据正确解码到我的对象模型中?

我这里有一个(非)工作示例:https://play.golang.org/p/qaYhKvJ65J3我不确定为什么会出现以下数据:alertData:=`{"Id":0,"Version":0,"OrgId":1,"DashboardId":61,"PanelId":84,"Name":"{qa-dev}{stats-pipeline}TopologyMessageAge(aggregator)alert","Message":"","Severity":"","State":"","Handler":1,"Silenced":false,"ExecutionError":"","F

go - base64解码然后json解码: base64. NewDecoder EOF错误和json无效字符错误

我正在尝试对HTTP请求进行base64解码,然后使用JSON解码器对其进行解码。我尝试了两种实现base64解码器的方法:funcdecode(encoded[]byte)([]byte,error){buff:=new(bytes.Buffer)decoder:=base64.NewDecoder(base64.StdEncoding,buff)_,err:=decoder.Read(encoded)returnbuff.Bytes(),err}此函数返回EOF错误。去Playground链接:https://play.golang.org/p/038rEXWYW6qfuncdec

json - 嵌套结构的解码字段不起作用

给定以下结构typeFoostruct{Thingtime.Duration`json:"thing"`}typeBarstruct{FooEntrytime.Duration`json:"entry"`}我想自定义time.Duration格式并从json字符串加载Bar值,例如:{"thing":"hour","entry":"second"}所以我为Foo和Bar(https://play.golang.org/p/6v71eG_Xr98)覆盖了UnmarshalJSON:packagemainimport("encoding/json""fmt""time")typeFoost