我正在构建逻辑应用程序工作流程,我需要使用 if 条件处理第三个 API 服务返回的 2 种不同类型的响应。
API 能够正确处理数据时的 API 响应看起来非常像这样:
[ { "Input": { "Address": "", "Address1": "Sageweg 27", "Address2": "Neuenburg", "Address3": "", "Address4": "", "Address5": "", "Address6": "", "Address7": "", "Address8": "", "Country": "DEU", "SuperAdministrativeArea": "", "AdministrativeArea": "", "SubAdministrativeArea": "", "Locality": "", "DependentLocality": "", "DoubleDependentLocality": "", "Thoroughfare": "", "DependentThoroughfare": "", "Building": "", "Premise": "", "SubBuilding": "", "PostalCode": "79395", "Organization": "", "PostBox": "" }, "Matches": [ { "AQI": "A", "AVC": "V44-I44-P6-100", "Address": "Sägeweg 27,79395 Neuenburg Am Rhein", "Address1": "Sägeweg 27", "Address2": "79395 Neuenburg Am Rhein", "AdministrativeArea": "Baden-Württemberg", "CountryName": "Germany", "DeliveryAddress": "Sägeweg 27", "DeliveryAddress1": "Sägeweg 27", "GeoAccuracy": "P4", "GeoDistance": "0.0", "HyphenClass": "C", "ISO3166-2": "DE", "Country": "DE", "ISO3166-3": "DEU", "ISO3166-N": "276", "Latitude": "47.807820", "Locality": "Neuenburg Am Rhein", "Longitude": "7.569160", "MatchRuleLabel": "Rlfnp", "PostalCode": "79395", "PostalCodePrimary": "79395", "Premise": "27", "PremiseNumber": "27", "SubAdministrativeArea": "Reg.-Bez. Freiburg", "Thoroughfare": "Sägeweg" } ] }, { "Input": { "Address": "", "Address1": "Schubartstr. 111", "Address2": "Bietigheim-Bissingen", "Address3": "74321", "Address4": "", "Address5": "", "Address6": "", "Address7": "", "Address8": "", "Country": "DEU", "SuperAdministrativeArea": "", "AdministrativeArea": "", "SubAdministrativeArea": "", "Locality": "", "DependentLocality": "", "DoubleDependentLocality": "", "Thoroughfare": "", "DependentThoroughfare": "", "Building": "", "Premise": "", "SubBuilding": "", "PostalCode": "", "Organization": "", "PostBox": "" }, "Matches": [ { "AQI": "A", "AVC": "V44-I44-P6-100", "Address": "Schubartstr. 111,74321 Bietigheim-Bissingen", "Address1": "Schubartstr. 111", "Address2": "74321 Bietigheim-Bissingen", "AdministrativeArea": "Baden-Württemberg", "CountryName": "Germany", "DeliveryAddress": "Schubartstr. 111", "DeliveryAddress1": "Schubartstr. 111", "DependentLocality": "Bissingen", "GeoAccuracy": "P4", "GeoDistance": "0.0", "HyphenClass": "C", "ISO3166-2": "DE", "Country": "DE", "ISO3166-3": "DEU", "ISO3166-N": "276", "Latitude": "48.942220", "Locality": "Bietigheim-Bissingen", "Longitude": "9.106600", "MatchRuleLabel": "Rlfnp", "PostalCode": "74321", "PostalCodePrimary": "74321", "Premise": "111", "PremiseNumber": "111", "SubAdministrativeArea": "Reg.-Bez. Stuttgart", "Thoroughfare": "Schubartstr." } ] } ]
如果出现“错误”,则如下所示:
{ "Number": 18, "Description": "Missing or invalid parameters", "Cause": "A required parameter was not supplied of the value of a parameter cannnot be converted into the right type.", "Resolution": "Check the parameters passed and their values against the specification for this service." }
考虑到在成功情况下它是一个数组,而在错误情况下它是一个对象,如何设置 Parse JSON 操作的架构?
如果我之前再次问过这个问题,但我在此处粘贴的成功回复是错误的,非常抱歉。
感谢大家花时间提供帮助。
您可以使用下面给出的模式来解析成功和失败响应。
{
"oneOf": [
{
"type": "object",
"properties": {
"Number": {
"type": "integer"
},
"Description": {
"type": "string"
},
"Cause": {
"type": "string"
},
"Resolution": {
"type": "string"
}
},
"additionalProperties": false
},
{
"type": "array",
"items": {
"type": "object",
"properties": {
"Input": {
"type": "object",
"properties": {
"Address": {
"type": "string"
},
"Address1": {
"type": "string"
},
"Address2": {
"type": "string"
},
"Address3": {
"type": "string"
},
"Address4": {
"type": "string"
},
"Address5": {
"type": "string"
},
"Address6": {
"type": "string"
},
"Address7": {
"type": "string"
},
"Address8": {
"type": "string"
},
"Country": {
"type": "string"
},
"SuperAdministrativeArea": {
"type": "string"
},
"AdministrativeArea": {
"type": "string"
},
"SubAdministrativeArea": {
"type": "string"
},
"Locality": {
"type": "string"
},
"DependentLocality": {
"type": "string"
},
"DoubleDependentLocality": {
"type": "string"
},
"Thoroughfare": {
"type": "string"
},
"DependentThoroughfare": {
"type": "string"
},
"Building": {
"type": "string"
},
"Premise": {
"type": "string"
},
"SubBuilding": {
"type": "string"
},
"PostalCode": {
"type": "string"
},
"Organization": {
"type": "string"
},
"PostBox": {
"type": "string"
}
}
},
"Matches": {
"type": "array",
"items": {
"type": "object",
"properties": {
"AQI": {
"type": "string"
},
"AVC": {
"type": "string"
},
"Address": {
"type": "string"
},
"Address1": {
"type": "string"
},
"Address2": {
"type": "string"
},
"AdministrativeArea": {
"type": "string"
},
"CountryName": {
"type": "string"
},
"DeliveryAddress": {
"type": "string"
},
"DeliveryAddress1": {
"type": "string"
},
"DependentLocality": {
"type": "string"
},
"GeoAccuracy": {
"type": "string"
},
"GeoDistance": {
"type": "string"
},
"HyphenClass": {
"type": "string"
},
"ISO3166-2": {
"type": "string"
},
"Country": {
"type": "string"
},
"ISO3166-3": {
"type": "string"
},
"ISO3166-N": {
"type": "string"
},
"Latitude": {
"type": "string"
},
"Locality": {
"type": "string"
},
"Longitude": {
"type": "string"
},
"MatchRuleLabel": {
"type": "string"
},
"PostalCode": {
"type": "string"
},
"PostalCodePrimary": {
"type": "string"
},
"Premise": {
"type": "string"
},
"PremiseNumber": {
"type": "string"
},
"SubAdministrativeArea": {
"type": "string"
},
"Thoroughfare": {
"type": "string"
}
}
}
}
},
"additionalProperties": false
}
}
]
}
成功负载-
故障有效负载 -