在响应有效的JSON [英] Valid JSON in Response

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

问题描述

我工作的客户端和服务器应用程序并在一个有趣的问题来了。我们正在创造一个宁静的API和JSON响应到客户端通信。当执行DELETE,我们正在与一个空白的响应返回200 OK。我们的客户所得到的200行,但未能在解析JSON。

I am working on a client and server application and came across an interesting problem. We are creating a restful API and communicating to the clients with JSON responses. When doing a DELETE, we are returning a 200 OK with a blank response. Our clients are getting the 200 OK, but failing on parsing the JSON.

我们完全理解失败的解析(没有什么解析),但我们有一个更大的问题。发送一个空白响应有效的JSON,或者我们应该回到 {} 或东西的效果呢?谢谢你。

We completely understand the failed parse (there is nothing to parse), but we had a bigger question. Is sending a blank response valid JSON, or should we be returning {} or something to that effect? Thanks.

推荐答案

HTTP有关DELETE方法/1.1定义

一个成功的响应应该是200(OK)如果响应包括
  实体描述状态,202(接受)如果操作还没有
  已颁布,或204(无内容)如果该行动已颁布,但
  响应不包括一个实体。

A successful response SHOULD be 200 (OK) if the response includes an entity describing the status, 202 (Accepted) if the action has not yet been enacted, or 204 (No Content) if the action has been enacted but the response does not include an entity.

所以,如果你的服务器被立即删除的项目,然后建议的答复是:

So if your server is deleting the item immediately, then the suggested responses would be:


  • 200 OK - 返回某种状态code(比如一个true或字符串说成功)

  • 204无内容 - 返回任何结果,并让您的客户端小心这种反应,而不是试图JSON解析,同时还知道请求成功

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

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