草庐IT

json-api

全部标签

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"`/

json - 为什么在 Go 中来自 REST 端点的 JSON 中到处都是 "\n"?

我想返回一些从API获取的JSON,并在我的Go程序中抛出到REST端点。数据进来时没问题,但不知何故,编码弄乱了JSON?示例代码:varstockSymbols=[]string{"GOOGL","TSLA","AAPL",}varMarketDataMap=make(map[int]interface{})funcGetStockMarketData(){forindex,stockSymbol:=rangestockSymbols{varrequestLink=fmt.Sprintf("http://somelinkhere/API%sand%v",stockSymbol,ap

json - 在 JSON 对象中发送数组时出错

为了用IrisGo发送这个JSON{"response_type":"in_channel","text":"It's80degreesrightnow.","attachments":[{"text":"Partlycloudytodayandtomorrow"}]}我正在尝试这个但是没有用ctx.JSON(iris.Map{"text":"It's80degreesrightnow.","response_type":"in_channel","attachments":[{"text":"Partlycloudytodayandtomorrow"}],})因为附件行出现如下错误s