gpt4 book ai didi

json - BizTalk JSON 反序列化

转载 作者:数据小太阳 更新时间:2023-10-29 01:57:56 26 4
gpt4 key购买 nike

我必须通过 BizTalk 连接 REST 服务。该服务返回一个 JSON 响应,如下所示。当 BizTalk 响应端口尝试解码 JSON 消息时,我收到有关 JSON 到 XML 转换的错误。发生此错误是因为 JSON 消息中嵌入了 HTML 标记。

错误:

(There was a failure executing the response(receive) pipeline: "Avansas.Paritus.Suggest.T.JSONReceive, Avansas.Paritus.Suggest.T, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7b2984270a9ffd13" Source: "JSON decoder" Send Port: "Avansas.Ibrahim.Suggest.T.SendPort" URI: "api1.test.com/services/rest"; Reason: Unexpected character encountered while parsing value: <. Path '', line 0, position 0. )

例如:

如下响应消息在 JSON 中有一个标签元素。 Label 元素包含带有 html 标记 (City) 的文本,这就是为什么当 BizTalk 尝试将 JSON 转换为 XML 时出现错误的原因。我认为 BizTalk 尝试将 JSON 转换为图 2,但我想将其转换为图 3。

我该如何解决这个问题?

有没有什么方法可以在没有任何模式的情况下通过编排进行直通传输?

图1

{
"suggestion": [
{
"id": "[31 31 31 30 30 39]",
"label": "Global <b>City</b> 2. Etap Global <b>Cıty</b> ",
"value": "Global <b>City</b> 2. Etap Villaları "
},
{
"id": "[39 33 36 32 35 36]",
"label": "<b>City</b> Aqua Villas Sk. Kuşadası Aydın",
"value": "<b>City</b> Aqua Villas Sk. Kuşadası Aydın"
}
]
}

图 2:

<root>
<suggestion>
<id>[31 31 31 30 30 39]</id>
<label>Global
<b>City</b> 2. Etap Global
<b>Cıty</b>
</label>
<value>Global
<b>City</b> 2. Etap Villaları
</value>
</suggestion>
<suggestion>
<id>[39 33 36 32 35 36]</id>
<label>
<b>City</b> Aqua Villas Sk. Kuşadası Aydın
</label>
<value>
<b>City</b> Aqua Villas Sk. Kuşadası Aydın
</value>
</suggestion>
</root>

图 3:

<root>
<suggestion>
<id>[31 31 31 30 30 39]</id>
<label>Global
&lt;b&gt;City&lt;/b&gt; 2. Etap Global
&lt;b&gt;Cıty&lt;/b&gt;
</label>
<value>Global
&lt;&gt;City&lt;/b&gt; 2. Etap Villaları
</value>
</suggestion>
<suggestion>
<id>[39 33 36 32 35 36]</id>
<label>
&lt;b&gt;City&lt;/b&gt; Aqua Villas Sk. Kuşadası Aydın
</label>
<value>
&lt;b&gt;City&lt;/b&gt; Aqua Villas Sk. Kuşadası Aydın
</value>
</suggestion>
</root>

我的服务也可以返回 xml 响应,当我尝试处理 xml 响应时出现以下错误。

XML Error There was a failure executing the response(receive) pipeline: "Microsoft.BizTalk.DefaultPipelines.XMLReceive, Microsoft.BizTalk.DefaultPipelines, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Source: "XML disassembler" Send Port: "aaa.bbb.Suggest.T.SendPort" URI: "https://api1.test.com/services/rest" Reason: Finding the document specification by message type "html" failed. Verify the schema deployed properly

响应xml如下所示

<?xml version="1.0" encoding="UTF-8"?>
<suggestions>
<suggestion>
<id>111011</id>
<label>Global &lt;b&gt;Cıty&lt;/b&gt; 1. Etap Vıllaları Sokak</label>
<value>Global Cıty 1. Etap Vıllaları Sokak</value>
</suggestion>
<suggestion>
<id>111009</id>
<label>Global &lt;b&gt;Cıty&lt;/b&gt; 2. Etap Vıllaları Sokak</label>
<value>Global Cıty 2. Etap Vıllaları Sokak</value>
</suggestion>
</suggestions>

最佳答案

使用这个模式:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified" elementFormDefault="unqualified" targetNamespace="http://BizTalk_Server_Project1.JSONSchema1" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Root">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="suggestion">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="id" type="xs:string" />
<xs:element minOccurs="0" name="label" type="xs:string" />
<xs:element minOccurs="0" name="value" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

这条管道:

JSON Pipeline

生成此消息:

<ns0:Root xmlns:ns0="http://BizTalk_Server_Project1.JSONSchema1">
<suggestion>
<id>[31 31 31 30 30 39]</id>
<label>Global &lt;b&gt;City&lt;/b&gt; 2. Etap Global &lt;b&gt;Cıty&lt;/b&gt; </label>
<value>Global &lt;b&gt;City&lt;/b&gt; 2. Etap Villaları </value>
</suggestion>
<suggestion>
<id>[39 33 36 32 35 36]</id>
<label>&lt;b&gt;City&lt;/b&gt; Aqua Villas Sk. Kuşadası Aydın</label>
<value>&lt;b&gt;City&lt;/b&gt; Aqua Villas Sk. Kuşadası Aydın</value>
</suggestion>
</ns0:Root>

关于json - BizTalk JSON 反序列化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31149288/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com