昨天晚上到今天下午,查了快一天百度也没找到解决办法~人已经崩溃了~ 用的 Gorm 处理~对 Go 也不太熟悉~感觉这搞来搞去真的要高血压了~
首先,我拿到了一个 json ,长这样:
{
"version": "0.0.1",
"success": true,
"result": [
{
"service_tag": "12345T",
"ip_lan": "10.10.10.10",
"ip_wan": "0.0.0.0",
"idc": "MH",
"tags": [
{
"tag_category": "environment",
"value": "live"
},
{
"tag_category": "idc",
"value": "sg"
},
{
"tag_category": "application",
"value": "stoc"
},
{
"tag_category": "function",
"value": "redis"
},
{
"tag_category": "server_standard",
"value": "S1"
},
{
"tag_category": "office",
"value": "SG"
}
],
"memory": "1250GB",
"cpu_count": 4800,
"state": "operating"
}
]
}
随后我把 JSON 的 tags 标签存到了 mysql 中,长这样:
[{"tag_category":"environment","value":"live"},{"tag_category":"idc","value":"sg"},{"tag_category":"application","value":"stoc"},{"tag_category":"function","value":"redis"},{"tag_category":"server_standard","value":"S1"},{"tag_category":"office","value":"SG"}]
到这里都没有什么问题,可是我通过 mysql 自带的查询语句查所有数据的时候,查出的并不是 json 格式了~ tags 的内容被当成了字符串,被加了前缀"和后缀",内容中也含有转义字符\
{
"version": "0.0.1",
"success": true,
"result": [
{
"ID": 1,
"ServiceTag": "test",
"IPLan": "10.10.10.11",
"IPWan": "0.0.0.0",
"Idc": "SZ",
"State": "",
"Memory": "128GB",
"CpuCount": 48,
"Tags": "test",
"CcUName": "",
"CcService": "",
"CreatedAt": 1231,
"UpdatedAt": 1637956306,
"PState": "已完成 11111"
},
{
"ID": 2,
"ServiceTag": "123456T",
"IPLan": "10.10.10.10",
"IPWan": "0.0.0.0",
"Idc": "BJ",
"State": "operating",
"Memory": "125GB",
"CpuCount": 48,
"Tags": "[{\"tag_category\":\"environment\",\"value\":\"live\"},{\"tag_category\":\"idc\",\"value\":\"sg\"},{\"tag_category\":\"application\",\"value\":\"stoc\"},{\"tag_category\":\"function\",\"value\":\"redis\"},{\"tag_category\":\"server_standard\",\"value\":\"S1\"},{\"tag_category\":\"office\",\"value\":\"SG\"}]",
"CcName": "",
"CcService": "",
"CreatedAt": 1638005233,
"UpdatedAt": 1638005233,
"PState": "未解决"
}
]
}
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.