XML-To-JSON策略 [英] XML-To-JSON Policy

查看:72
本文介绍了XML-To-JSON策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Team, 


1.我们已在XML Reposne上应用XML TO JSON策略。该节点具有相同名称类型和类型的2个属性,如下所示


< dropdown type =" menu">

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < url>#< / url>

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < text>关于我们< / text>

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < type> marketing< / type>


< / dropdow>


预期回复是 


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "type":[

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "menu","
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "营销"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; ],
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; " url":"#",&
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "text":""关于我们",


但是输出不会将此视为数组,广告产生2种不同的属性类型,@ type如下所示


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "@ type":" menu",$
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; " url":"#",&
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; " text":" About Us",
  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; "type":" marketing",



有没有办法在XML-To-JSON中实现这一点



2。我们的文字字段包含此< text><![CDATA [关于我们]]>< / text>正在返回如下所示的回复


  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;  " text":{

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; " $ cdata_section":" About Us"

  &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; },


如何解决此问题




谢谢和问候


SabariNadh。



解决方案

我相信
xml-to-json policy
非常类似于
博客
。这也是
Json.NET实施
的方式。


此转换方法旨在保留XML有效内容的完整内容,并且还能够将输出JSON转换回原始XML。


无法自定义此行为,但您应该能够使用

使用液体模板的set-body策略


Hello Team, 

1.We have applied XML TO JSON policy on our XML Reposne. The node hase 2 proerties with same name type and type like below

<dropdown type="menu">
                <url>#</url>
                <text>About Us</text>
                <type>marketing</type>

</dropdow>

The expected response is 

                        "type": [
                            "menu",
                            "marketing"
                        ],
                        "url": "#",
                        "text": "About Us",

but the output is not considering this as array, ad producing 2 different properties type and @type as below

                        "@type": "menu",
                        "url": "#",
                        "text": "About Us",
                        "type": "marketing",

Is there any way to acheive this in XML-To-JSON

2. our Text fields having this <text><![CDATA[About Us]]></text> are returning response like below

                             "text": {
                                    "$cdata_section": "About Us"
                                },

How to resolve this issues

Thanks and Regards

SabariNadh.

解决方案

I believe the conversion made by the xml-to-json policy is pretty similar to how its described in this blog. This is also how Json.NET implements it as well.

This conversion methodology aims to preserve the complete content of the XML payload and also be able to convert the output JSON back to the original XML.

There is no way to customize this behavior but you should be able to map either the input XML or output JSON into the form you need by using the set-body policy using liquid templates.


这篇关于XML-To-JSON策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆