我正在尝试将 json 数据映射到map[string]interface{}
使用 reflect 和 recursion 。该函数按预期工作,但当涉及到嵌套 json 时,它并没有映射所有值。
我有以下 json 结构:
{
"r_id" : "123456",
"title" : "brand new restarant with changed name",
"address": {
"city": {
"id": "25",
"name": "Dhaka"
},
"postal":"1213"
},
"description" : "here are some new desciption ..."
}
我正在尝试将其映射到字段的字符串和值的接口,其中字段的字符串(如果它是嵌套的)将与点连接.
。例如,映射title
仅map[title:brand new restarant with changed name]
适用于城市name
,id
它将是map[address.city.id:25 address.city.name:Dhaka]
我写了这个脚本。
我的目标是在一个映射中key
,value
其中嵌套 json 的键将是一个字符串,例如parent.child.child.child
它是 ajson path
并且值将是最后一个孩子的值
最终输出应该是这样的:map[address.city.id:25 address.city.name:Dhaka address.postal:1213 r_id:123456 title:brand new restarant with changed name descripton:here are some new desciption ...]
但它会打印map[address.city.id:25 address.city.name:Dhaka r_id:123456 title:brand new restarant with changed name]
But not all string field like description
and state
of address
我想我需要对类型进行排序然后运行递归函数?