草庐IT

json_parser

全部标签

json - 为什么我要将 map 转换为 json,map 包含列表值,转换为 json 后什么都没有

funcTest_JsonTtransfer(t*testing.T){uid:="306"phoneList:=list.New()phoneList.PushBack("18513622928")fmt.Println("phoneList=======",phoneList.Len())jsonPhoneList,err:=json.Marshal(phoneList)iferr!=nil{fmt.Println("error:",err)}fmt.Println("jsonPhoneList=======",string(jsonPhoneList))idCardList:=l

json - 解码未知格式的 JSON 数据

这个问题在这里已经有了答案:UnmarshalJSONwithsomeknown,andsomeunknownfieldnames(8个答案)关闭3年前。我的JSON格式如下:{'Math':[{'Student1':100.0,'timestamp':Timestamp('2017-06-2615:30:00'),'Student2':100.0,'Student3':97.058823442402414},{'Student1':93.877550824911907,'timestamp':Timestamp('2017-06-2615:31:00'),'Student2':100

go - 序列化为JSON动态结构

所有使用JSON的示例都描述了如何序列化为JSON简单类型或用户类型(如结构)。但我有不同的情况:a)我不知道我的类型/对象的字段b)每个对象都有不同的类型。这是我的案例的伪代码:while`select*fromitem`dowhile`selectfieldname,fieldvaluefromfieldswherefields.itemid=item.id`do...对于我数据库中的每个实体,我都获得了字段名称和字段值。结果我需要得到这样的东西:{"item.field1":value,..."item.fieldN":value,"custom_fields":{"fields

json - 在 Go 中使用数组解析 JSON 文件

以下是我尝试解析的JSON文件(如果有人好奇,可以使用OpenWeatherMapAPI)。内置的encoding/json做得很好。当我使用json.Unmarshal(testJson,&parsed)时,大多数JSON文件都被正确解析。然而,随着它的格式化方式,“天气”让我很头疼。我用parsedMap:=parsed.(map[string]interface{})解析了encoding/json生成的文件,当我尝试引用时它起作用了键,值对与键“main”。使用fmt.Println(),值为map[temp:280.32pressure:1012humidity:81temp

json - 为什么 golang 没有编码 json 对象?

这个问题在这里已经有了答案:json.Marshal(struct)returns"{}"(3个答案)关闭5年前。我想知道为什么以下没有成功编码到json?我正在尝试使用一个非常简单的示例来学习json包。packagemainimport("encoding/json""fmt")typeMessagestruct{usernamestring`json:"name"`messagestring`json:"message"`}funcmain(){varm=Message{username:"hello",message:"world",}js,_:=json.Marshal(m)

json - 创建 JSON 数组和 JSON 对象

我正在为Go开发一个应用程序。该应用正在从第三方获取JSON数据。我不知道如何创建json对象并将其附加到json数组。发生的事情是我有一个循环,每个元素都收到了。下面是代码:typePastWeekWeatherArraystruct{PastWeekWeather[]PastDayWeather`json:"array"`}typePastDayWeatherstruct{DayWeatherstring`json:"day"`}funcget_weather(ctxcontext.Context,placestring,datestring)(string,error){varm

json - 如何将 JSON 文档中的字符串值解码为 int 类型的变量?

我的结构:typeUserstruct{FirstNamestring`json:"firstname,omitempty"validate:"required"`LastNamestring`json:"lastname,omitempty"validate:"required"`NumberofDaysint`json:"numberofdays,string"validate:"min=0,max=100"`}NumberofDays的值作为字符串从服务器传递,但我想检查它是否在范围内并存储为int。例如:user:=&User{"Michael","Msk","3"}我收到“无

json - 如何解析由 cryptocompare API 生成的 JSON?

关闭。这个问题需要debuggingdetails.它目前不接受答案。编辑问题以包含desiredbehavior,aspecificproblemorerror,andtheshortestcodenecessarytoreproducetheproblem.这将有助于其他人回答问题。关闭5年前。Improvethisquestion我正在尝试使用此API端点解析一些JSON。https://www.cryptocompare.com/api/data/coinlist/我可以看到它使请求正常,然后我尝试解码响应的主体,它返回大量随机数。如果我从调试器复制正文值,我会得到以下结果。(

json - 转到库映射 json 键以清理输出

是否有任何Go库可以在将Json输出发送给用户之前对其进行整理?我们可以解码为一个结构并手动执行此操作,但我们想知道是否有任何库可以更轻松地将key提取到结构中,我们可以将其编码并发送给用户? 最佳答案 由于Go处理JSON编码和取消编码的方式,简短的回答并非如此。处理用例的常见模式只是定义一个Response结构。一个典型的例子如下:typeUserstruct{//fields}//ResponsetypeusedwhentheuserisaskingabouttheirownfieldstypePrivateUserRespo

json - 在 GO lang 中使用 API 时如何将 JSON 转换为 Go 类型定义

我正在构建一个使用API的应用程序,然后还将json数据保存到golang结构中,稍后我将制作端点,为某些计算提供结果。我已经实现了使用API,具有挑战性的部分是如何以go理解的方式保存数据。哪种方法合适?下面是我发起请求时的JSON格式。我感兴趣的key只有TimeSeries(1min)JSON{"MetaData":{"1.Information":"Intraday(1min)pricesandvolumes","2.Symbol":"MSFT","3.LastRefreshed":"2018-05-2416:00:00","4.Interval":"1min","5.Outp