简体   繁体   English

WSO2 EI-如何处理API中格式错误的JSON请求

[英]WSO2 EI - how to handle malformed JSON requests in API

I have created an API in WSO2 EI. 我已经在WSO2 EI中创建了一个API。 API is expecting the requests to be send as JSON. API希望请求以JSON的形式发送。 If it is a malformed JSON which is sent, then I should be able to receive it and make appropriate changes to make it a proper JSON. 如果发送的是格式错误的JSON,则我应该能够接收它并进行适当的更改以使其成为正确的JSON。

Any help is much appreciated. 任何帮助深表感谢。

As we are using json-eval($.) to get the message to property, it is not working for me. 由于我们使用json-eval($。)将消息发送到属性,因此它对我不起作用。 What else i could try instead of json-eval to get the message as string. 还有什么我可以尝试代替json-eval来获取消息作为字符串。

WSO2 EI has the property force.json.message.validation , which can be used to validate incoming JSON payload. WSO2 EI具有force.json.message.validation属性,可用于验证传入的JSON有效负载。 Please refer doc to configure this property in 'passthru-http.properties' file. 请参考文档以在“ passthru-http.properties”文件中配置此属性。

Once the property is configured, if there is a malformed JSON payload in the request, the mediation flow will be directed to the fault/error sequence. 配置完属性后,如果请求中包含格式错误的JSON有效负载,则中介流将定向到故障/错误序列。 So, you can define the mediation logic to make appropriate changes to the malformed content within the fault sequence of your API. 因此,您可以定义中介逻辑,以在API故障序列内对格式错误的内容进行适当的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM