Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xquery 如何从jsoniq或javascript中的json文档中获取所有字符串?_Xquery_Jsoniq - Fatal编程技术网

Xquery 如何从jsoniq或javascript中的json文档中获取所有字符串?

Xquery 如何从jsoniq或javascript中的json文档中获取所有字符串?,xquery,jsoniq,Xquery,Jsoniq,我试图将json字符串的所有值作为单个字符串获取。例如 在xquery xml中 let $x := <a> welcome to the world of <b> JSONiq </b></a> return string($x) 结果应该是一样的欢迎来到JSONiq的世界 如果你也知道javascript,那就太好了 首先需要使用libjn:values或其定义获取所有值,然后可以使用fn:string join获取单个字符串: 所以 或 这

我试图将json字符串的所有值作为单个字符串获取。例如 在xquery xml中

let $x := <a> welcome to the world of <b> JSONiq </b></a>
return string($x)
结果应该是一样的
欢迎来到JSONiq的世界


如果你也知道javascript,那就太好了

首先需要使用
libjn:values
或其定义获取所有值,然后可以使用
fn:string join
获取单个字符串:

所以


这也可能返回“JSONiqwelcome to the world of”,因为对象键是无序的

查找递归JSONiq脚本以进行尝试。 只需执行typeswitch和递归调用即可:

declare function local:strings($v as item()) as xs:string*
{
  typeswitch ($v)
    case $object as object() return
      for $k in jn:keys($object)
        return local:strings($object($k))
    case $array as array() return
      for $member in jn:members($array)
        return local:strings($member)
    default return $v
};

let $y := {"a":"welcome to the world of", "b":" JSONiq", "x":{"d":"m"}}

return string-join(local:strings($y), "@")
“@”仅用于显示边界的位置,可替换为“”:


赫尔曼。

你好,谢谢,首先我无法测试。第二,它不存在;不适用于复杂的json。如果在javascript中也有解决方案,那就太好了。感谢您希望它为复杂的json打印什么?您可以在这里看到Benito的查询结果:@wcandillon请尝试这个(使用复杂的json):@PrakashThapa:在那里您可以递归调用它
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(.)), "")
declare function local:strings($v as item()) as xs:string*
{
  typeswitch ($v)
    case $object as object() return
      for $k in jn:keys($object)
        return local:strings($object($k))
    case $array as array() return
      for $member in jn:members($array)
        return local:strings($member)
    default return $v
};

let $y := {"a":"welcome to the world of", "b":" JSONiq", "x":{"d":"m"}}

return string-join(local:strings($y), "@")
welcome to the world of@JSONiq@m