golang在json编组期间忽略空字符串

时间:2019-05-06 19:52:14

标签: json go

这是我的代码:

fmt.Println("before Marshalling: ", res4)
warehouseData, _ := json.Marshal(res4)
fmt.Println("after Marshalling", string(warehouseData))

此处输出:

before Marshalling:  [map[cellidx:1A13 description:CONN FFC BOTTOM 24POS 0.50MM R/A footprint:<nil> temperature:<nil> help_url: part_number:SFV24R-1STE1HLF ref_supplier:<nil> qty:10 supplier_link:http://www.digikey.com/product-detail/en/amphenol-fci/SFV24R-1STE1HLF/609-4320-1-ND/2626771 notes:<nil>]]
after Marshalling [{"cellidx":"1A13","description":"CONN FFC BOTTOM 24POS 0.50MM R/A","footprint":null,"help_url":"","notes":null,"part_number":"SFV24R-1STE1HLF","qty":10,"ref_supplier":null,"supplier_link":"http://www.digikey.com/product-detail/en/amphenol-fci/SFV24R-1STE1HLF/609-4320-1-ND/2626771","temperature":null}]

问题是res4变量的类型为[]map[string]interface{}。例如。该数据是从Postgresql请求中获得的,结构未知。 如果由于数据结构未知而无法使用omitempty技巧,如何从结果JSON中忽略空字符串?

0 个答案:

没有答案