如何编写包含空格的 JSON 字段的 XPath 表达式?

huangapple go评论62阅读模式
英文:

How to write the Xpath for the json field having white space?

问题

我想为一个包含空格的 JSON 字段编写 XPath 表达式。

[    
    {"name":"Ram", "email id":"ram@gmail.com", "age":23},    
    {"name":"Shyam", "email id":"shyam23@gmail.com", "age":28}
]

我尝试使用以下方式获取 email id:

?1?email id

当我在开源项目中搜索时,我了解到在 XPath 3.1 中是不可能的。XPath 4.0 支持上述方式:

?1?'email id'

有人可以帮助我如何使用 XPath 4.0 吗?是否需要添加任何依赖项?

英文:

I want to write the xpath for a json field which is having white spaces in it.

[    
    {"name":"Ram", "emai ld":"ram@gmail.com", "age":23},    
    {"name":"Shyam", "email id":"shyam23@gmail.com", "age":28}
]

I tried as below to get the email id:

?1?email id

When I searched in open source I got to know this is not possible in Xpath 3.1. Xpath 4.0 supports the above as

?1?'email id'

Can somebody helps how I can use Xpath 4.0? Meaning any dependency that I need to add?

答案1

得分: 1

你需要将字符串字面值放在括号中:

?1?('电子邮件ID')
英文:

You need to put the string literal in parentheses:

?1?('email id')

答案2

得分: 1

或者只需使用?1('email id')调用地图。

英文:

Or just call the map with e.g. ?1('email id').

huangapple
  • 本文由 发表于 2023年8月8日 20:56:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/76859794.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定