json序列化:无法处理长度为3的序列开始位置

json序列化:无法处理长度为3的序列开始位置,json,xml,xquery,Json,Xml,Xquery,我正在尝试将一个xml转换为json,其中包含了关于书籍、作者、价格和其他一些数据biblio.xml的信息,但是错误是 json serialization: cannot handle a sequence of length 3 start location 一直显示,我不知道发生了什么,我有搜索蹄来转换它,这种方式应该工作,我甚至不明白错误的意思 我想要的结果是: [{ "author": [ "W. Stevens" ], "title":"TCP\/IP Illust

我正在尝试将一个xml转换为json,其中包含了关于书籍、作者、价格和其他一些数据biblio.xml的信息,但是错误是

json serialization: cannot handle a sequence of length 3 start location
一直显示,我不知道发生了什么,我有搜索蹄来转换它,这种方式应该工作,我甚至不明白错误的意思

我想要的结果是:

    [{  "author": [ "W. Stevens"  ],  "title":"TCP\/IP Illustrated", "year":"1994"},
     {  "author": [ "W. Stevens" ],  "title":"Advanced Programming ...", "year":"1992" },
     {  "author": [ "Serge Abiteboul", "Peter Buneman",  "Dan Suciu"  ],  "title":"Data on the Web", "year":"2000"  },
     ]
我的biblio.xml是这样的:

 <bib>
        <book year="1994">
            <title>TCP/IP Illustrated</title>
            <author>
                <last>Stevens</last>
                <first>W.</first>
            </author>
            <publisher>Addison-Wesley</publisher>
            <price>65.95</price>
        </book>
    </bib>    
        <book year="1992">
        <title>Advanced Programming in the Unix environment</title>
        <author>
            <last>Stevens</last>
            <first>W.</first>
        </author>
        <publisher>Addison-Wesley</publisher>
        <price>65.95</price>
    </book>
    <book year="2000">
        <title>Data on the Web</title>
        <author>
            <last>Abiteboul</last>
            <first>Serge</first>
        </author>
        <author>
            <last>Buneman</last>
            <first>Peter</first>
        </author>
        <author>
            <last>Suciu</last>
            <first>Dan</first>
        </author>
        <publisher>Morgan Kaufmann Publishers</publisher>
        <price>39.95</price>
    </book>

I

我想您需要一个数组,其中包含三个映射,每个book元素对应一个映射:

而您的方法返回三个数组,每本书一个数组

网上样本

如果我们为…更换。。跟我一起去!运算符表达式更紧凑:

array {
/bib/book ! map{
       "author":  array { author/(first || ' ' || last)},
       "title": title/data(),
       "year" : @year/data()
  }
}
array {
for $books in (doc('test2018032201.xml')/bib/book) 
return 
   map{"author":  array { $books/author/(first || ' ' || last)},
       "title": $books/title/data(),
       "year" : $books/@year/data()
  }
}
array {
/bib/book ! map{
       "author":  array { author/(first || ' ' || last)},
       "title": title/data(),
       "year" : @year/data()
  }
}