草庐IT

api_response_json

全部标签

json - 在结构映射中存储/解码 json 的最佳方式

我在结构中有一个映射如下:typeRedstruct{**otherTelmap[string]string`json:"Tel"`}我收到的数据json格式如下{"Params":[{"rewew":"tref"},{"Value":"x"},....]}我正在寻找用数据填充我的结构的最有效方法,以便Tel["rewew"]="tref"Tel["Value"]="x"对于其余值,当执行此操作时这些值更简单时,它可以正常工作:vartReddecode:=json.NewDecoder(req.Body)decode.Decode(&t)但是我在使用map时遇到了问题

json - exec.Command 使用 JSON 负载转义变量

预先感谢您,因为我已经在这上面花了2天时间。这是一个有效的curl命令。curl-kulogin:pass-XPOST-H'Content-Type:application/json'-d'{"type":"page","title":"Testpage","space":{"key":"ITDept"},"body":{"storage":{"value":"BlankPage.","representation":"storage"}}}'https://confluence/rest/api/content我需要使用exec.Command来执行它。考虑到现在在Go中,我已经尝试

json - 将纪元时间戳解码为 time.Time

使用此结构运行Decode()会产生“时间戳”列错误:typeMetricsstruct{Idint`orm:"column(id);auto"`Namestring`orm:"column(name);size(255);null"json:"metric_name"`json:"lon"`Timestamptime.Time`orm:"column(timestamp);type(datetime)"json:"timestamp;omitempty"`}错误:parsingtime"1352289160"as""2006-01-02T15:04:05Z07:00"":cannot

json - JSON 响应结构

我正在尝试研究此JSON响应的类型结构。来自CryptoWatchhttps://api.cryptowat.ch/markets/kraken/btcusd/ohlc?periods=60{"result":{"60":[[1490733900,1027.001,1027.001,1027,1027,0.024999999],[1490733960,1027,1027,1027,1027,12.61904],[1490778360,1037.749,1037.749,1037.749,1037.749,0.0052474597]]},"allowance":{"cost":1234,

json - 在 Go 中读取 json 文件值

这个问题在这里已经有了答案:JSONanddealingwithunexportedfields(2个答案)关闭5年前。我有一个配置文件。我想从该文件中获取特定值。这是我的代码:packagemainimport("fmt""os""encoding/json")typeConfigurationstruct{consumer_keystringconsumer_secretstringaccess_tokenstringaccess_token_secretstringdb_namestringdb_userstringdb_passwordstringsecret_keystrin

json - 如何在 json 中显示结构的映射键和值

我有这段代码。packagemainimport("github.com/gin-gonic/gin"_"github.com/go-sql-driver/mysql")funcdivisionsHandler(c*gin.Context){divisions:=getDivisionRows()json:=make(map[int]string)fordivisions.Next(){vardDivisionerr:=divisions.Scan(&d.id,&d.name)json[d.id]=d.nameiferr!=nil{panic(err.Error())}}c.JSON(

json - 在 Golang 中解析 JSON 以绘制多边形

我正在用Go解析一个大型JSON文件,我只需要从JSON中提取特定的项目。它通常是一个非常大的文件,但最终,它变成了这样:"textAnnotations":[{"boundingPoly":{"vertices":[{"x":136,"y":119},{"x":5606,"y":119},{"x":5606,"y":3985},{"x":136,"y":3985}]},"description":"Description","locale":"en"},{"boundingPoly":{"vertices":[{"x":3420,"y":122},{"x":3439,"y":122}

go - 找不到包 "api/handlers"

好的,这个问题之前已经有人问过,我相信我已经查看了所有这些问题并测试了答案,但我将解释每个问题为何与我的情况不符。我可能错过了其中一个的答案,但我阅读了每一个并试图看看它是否适合我的情况Howtoimportlocalpackagesingo?我相信我的导入遵循答案的结构Gobuild:"Cannotfindpackage"(eventhoughGOPATHisset)我不确定这个是否完全相关,但我认为这不是同一个错误。Golang-Whycan'tIimportlocalpackageinGOPATH/src/projectbutcaninhomedirectory?我的导入路径不是

unit-testing - 在 golang 中模拟远程 api 调用

我正在尝试更好地编写调用远程api的模拟golang测试我可以使用httptest库很容易地模拟单个调用,但我是在处理多次调用单个端点调用的其他函数时卡住了。例如给定一个简单的创建函数funccreateItem(urlstring,productProduct)(int,error){//makerequestreturncreatedId,nil}我可以写一些像这样的测试funcTestCreateItem(t*testing.T){mock_ts:=httptest.NewServer(http.HandlerFunc(func(whttp.ResponseWriter,r*ht

json - 为非内置类型定义自定义解码

我们大多数人都知道可以使用JSON标签解码JSON对象:varjsonData=`{"name":"BrownBear"}`typeElephantstruct{Namestring`json:"name"`}这是因为string是内置类型。但是,如果Name不是内置类型,而我们想在不同的结构中使用这种类型怎么办?varjsonData=`{"name":"BrownBear"}`typeElephantstruct{NameName`json:"name"`//Unmarshallingfailshere}typeFelinestruct{NameName`json:"name"`/