我有以下JSON,我需要使用JSONPath来获得普通的name
值:
{
"single" : {
"id" : 1,
"name" : "Item name"
}
}
Expression that I used is $.single.name
but I always get an array:
[ "Item name" ]
而不是字符串值("Item name"
).
我有以下JSON,我需要使用JSONPath来获得普通的name
值:
{
"single" : {
"id" : 1,
"name" : "Item name"
}
}
Expression that I used is $.single.name
but I always get an array:
[ "Item name" ]
而不是字符串值("Item name"
).
but I always get an array:
这是注定要发生的.正如你在this documentation中看到的,在"结果"下(几乎在底部):
请注意,jsonPath的返回值是一个数组,它是
所以基本上它总是返回一个array.如果您需要数据作为其他类型,例如本例中的字符串,恐怕您必须自己进行转换.