我试图将 json 字符串的所有值作为单个字符串获取。例如 在 xquery xml 中
let $x := <a> welcome to the world of <b> JSONiq </b></a>
return string($x)
将返回欢迎来到 JSONiq 的世界
JSONiq 中以下文档的等效结果是什么:
let $y := {"a":"welcome to the world of ","b":" JSONiq"}
return xxxx($y)
结果应该是相同的欢迎来到 JSONiq 的世界
如果你也了解 javascript 那就太好了。
最佳答案
首先,您需要使用 libjn:values
或其定义获取所有值,然后您可以使用 fn:string-join
获取单个字符串:
所以
declare namespace libjn = "http://jsoniq.org/function-library";
let $y := {"a":"welcome to the world of ","b":" JSONiq"}
return string-join(libjn:values($y) ! string(), "")
或
let $y := {"a":"welcome to the world of ","b":" JSONiq"}
return string-join($y() ! string($y(.)), "")
这也可能返回“JSONiqwelcome to the world of”,因为对象键是无序的
关于xquery - 如何从 jsoniq 或 javascript 中的 json 文档获取所有字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21079385/