将具有可变属性的json对象转换为xml数组



Api的响应是{quot;内容":{quot;634331"[quot;找不到产品"],"634332":["找不到商品"],等等…

我很难将内容转换为xml:后的值捕获

<Content>
<__634331>Product could not be found</__634331>
<__634332>Product could not be found</__634332>
<__123104398>Product could not be found</__123104398>

这些值被解释为字段名称。

有没有一种方法可以将json对象转换为xml数组,如下所示:

<Content>
<res>
<key>634331</key>
<value>Product could not be found</value>
</res>
<res>
<key>634332</key>
<value>Product could not be found</value>
</res>

在JSON中,映射(或"对象"(中的键表示数据值而不是属性名是很常见的。不幸的是,这根本不能很好地映射到XML,而XML的等价物通常是类似的结构

<data key="__634331" value="Product could not be found"/>

没有一个自动转换器能够识别出这种转换是合适的。

我的建议是使用XSLT3.0模板规则进行自定义转换。我需要查看您的JSON的更多细节,并需要XML提供更详细的建议。

最新更新