如何提取没有属性名称的JSON值? [英] How to extract JSON values that does not have attribute names?
问题描述
{
"A1":{
"name":"Ad hoc",
"projectId":0
},
"X2":{
"name":"BBB",
"projectId":101
},
"AB":{
"name":"CCC",
"projectId":102
},
"recordsCount":3
}
对于此JSON,如何提取值?我需要像这样的输出
For this JSON, how to extract values? i need output like,
A1, Ad hoc
X2, BBB
AB, CCC
专家的意见表示赞赏.
推荐答案
分析
XPath 无法读取未命名的属性.它将始终导致异常.如果要获取值,则需要使用 JsonPath .
XPath can't read unnamed attributes. It will always result in an exception. If you want to get the values, you need to use JsonPath.
解决方案
即使那样,添加括号也很有意义,否则第一级也将被消耗:
Even then, it makes sense to add surrounding brackets, otherwise the first level will be consumed as well:
[
{
"A1":{
"name":"Ad hoc",
"projectId":0
},
"X2":{
"name":"BBB",
"projectId":101
},
"AB":{
"name":"CCC",
"projectId":102
},
"recordsCount":3
}
]
您可以在 jsonpath.com 上尝试正确的查询.对我来说(加上括号),路径$.*
有效.
You can try the correct query on jsonpath.com. For me (with the additional brackets) the path $.*
worked.
要提取值,如果使用文件或REST请求,则需要在Talend中使用 tExtractJSONFields 组件.
To extract the values, you need to use a tExtractJSONFields component in Talend if using a file or REST request.
对于带有字母数字标识符的字段,有效的JSON query
很容易[0]
.
A valid JSON query
could be easily [0]
for the field with alphanumeric identifiers.
这篇关于如何提取没有属性名称的JSON值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!