我正在为Github上的Go项目添加'array wildcards',名为jsonget。下面是我所说的阵列通配符意味着一个例子:在递归golang函数调用中键入
> echo "[{product:'coffee', price:2.10}, {product:'beer', price:3.80}]" | jsonget '*.price'
[2.10, 3.80]
我的分支代码为here
我遇到的问题是打字,GetValue
遇到*
字符时,递归,调用子表达式上的GetValue
,但类型总是以字符串形式返回。
例如,在测试文件,我给它这一块的JSON:
{
"inventory": [
{"name": "mountain bike", "price": 251.0},
{"name": "red wagon", "price": 90.10},
{"name": "kinesis advantage", "price": 300.0},
{"name": "a ticket to Mars", "price": 1200000000.0}
]
}
然后查询出inventory[*].price
,期待[251,90.1,300,1.2e+09]
,而是越来越["251","90.1","300","1.2e+09"]
。
我想避免在这里使用反射,但我没有看到另一种方式来做到这一点。
发布突出显示该问题的代码片段会很有帮助。 –
你的库在'main'包中定义 - 你应该修复你的项目结构。 – thwd