草庐IT

json_parser

全部标签

json - 在 Golang Structs 和 Json 之间动态转换

我想知道是否有一种方法可以在不使用数组的情况下动态扩展结构中共享相同数据类型的条目数。例如:typeMyHousestruct{Bedroom*Bedroom`json:"bedroom"`Kitchen*Kitchen`json:"Kitchen"`}typeKitchenstruct{Sink*Sink`json:"sink"`Oven*Oven`json:"oven"`}typeOvenstruct{Brandstring`json:"brand"`HobSize[]int`json:"hobs"`typeSinkstruct{Volumeint`json:"volume"`}t

json - 将结构编码为 json Go

我在将结构编码为json时遇到问题,我的代码是typeMainStructurestruct{Textstringjson:"text,omitempty"Array[]TestArrayjson:"test_array,omitmepty"}typeTestArraystruct{ArrayTextstringjson:"array_text,omitempty"}funcmain(){Test:=MainStructure{Text:"test",Array:[{ArrayText:"test1"},{ArrayText:"test2"}]}body:=new(bytes.Buff

go - 为什么要去 json.Unmarshal auto convert interface{} to map

程序会收到很多msg,msg有不同的struct“Data”,所以我定义了Msg结构体:typeMsgstruct{MsgTypeintDatainterface{}}typeData1struct{//msgtype1Datastruct}typeData2struct{//msgtype2Datastruct}func(msgStrstring){msg:=Msg{}iferr:=json.Unmarshal([]byte(msgStr),&msg);err!=nil{//logerr}switchmsg.MsgType{case1://convertmsg.Datatoatype

sql - 如何返回嵌套的 JSON?

我在PostgreSQL数据库中有3个表。问题表:|id(int)|text(text)||----------|--------------------------------------||1|Whatisyourfavoritecolor?||2|Whatisyourfavoritefootballclub?|OPTIONS表:|id(int)|text(text)||----------|-------------||1|red||2|blue||3|grey||4|green||5|brown|QUESTIONS_OPTIONS表:|question_id(int)|opti

go - 如何将一段结构编码为有效的 JSON

我正在编写Golangapi和客户端,但无法从api中的结构片段中获取有效的json。我在客户端中得到的结果如下所示。[{0Mark1234false}{0John3456false}]我需要这个json看起来像[{"id":0,"name":Mark,"pin":1234,"active":false}{"id":0,"name":John,"pin":3456,"active":false}]我找不到向我展示如何正确编码的示例,尽管有警告,这不是我能找到的任何内容的重复。虽然我的客户端成功地将JSON解析回结构,但我还需要它将JSON返回给请求它的IOS客户端。流程是API->AP

json - API 请求和响应

我想知道HTTP客户端是否可以在Go中使用不同的JSON对象发布特定的JSON对象和服务器响应。例如,客户端发送JSON对象请求正文{"nfNssaiAvailabilityUri":"string","taiList":[{"plmnId":{"mcc":"string","mnc":"string"},"tac":"string"}],"expiry":"2019-04-01T10:41:54.344Z"}响应主体为{"subscriptionId":"string","expiry":"2019-04-01T10:41:54.363Z","authorizedNssaiAvail

json - Golang 运行时 : goroutine stack exceeds 1000000000-byte limit

当我尝试Marshall嵌套结构的对象时出现此错误。我的结构看起来像:typeBlockchainstruct{blocks[]Block`json:"blocks"`difficultyint`json:"difficulty"`}typeBlockstruct{indexint`json:"index"`timestampstring`json:"timestamp"`datastring`json:"data"`previousHashstring`json:"previousHash"`hashstring`json:"hash"`nonceint`json:"nonce"`}

Go Lang 中的 JSON 结构到 csv

寻找在保留层次结构的同时将JSON读取结构导出为某种csv格式的想法。https://play.golang.org/p/jf2DRL1hC5K/*Expectedoutputinexcelfordatawrangling:AKey|BKey|CKey|DKeySomethingASomethingBSomethingCSomethingFSomethingASomethingBSomethingCSomethingGSomethingASomethingBSomethingC[1,2,3]*/我试过如下遍历结构for_,value:=rangemymodel{fmt.Println(

json - 尝试解析 JSON 并创建提取的 JSON

我正在尝试根据从API接收到的数据动态创建一个JSON对象。收到的示例数据:将数据解码到下面给出的CiItems结构中{"class_name":"test","configuration_items":[{"id":"ea09a24f-01ef-42ad-ab19-e0369341d9b3","ci_name":"makk","comments":null,"created_by":"mike","updated_by":"sam","created":"2019-08-02T21:16:35.656Z","updated":"2019-08-02T21:21:08.073Z","c

mongodb - 使用 golang 从 mongo 获取一段 json 字符串

我正在尝试使用golang中的以下代码从mongo获取一段json文本vara[]stringerr:=col..Find(nil).Select(bson.M{"_id":0}).All(&a)我得到错误Unsupporteddocumenttypeforunmarshalling:string我可以知道这样做的正确方法吗? 最佳答案 当您选择除_id之外的所有内容时,返回的将是一个仅包含剩余字段的文档。你可以这样做:typefieldDocstruct{Fieldstring`bson:"name"`}vara[]fieldDo