Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 有没有更好的方法来列出响应API请求的错误?_Json_Api - Fatal编程技术网

Json 有没有更好的方法来列出响应API请求的错误?

Json 有没有更好的方法来列出响应API请求的错误?,json,api,Json,Api,我正在构建一个JSON REST API。某些API操作需要属性。如果对这些操作发出的API请求没有所有必需的属性,API将返回4xx HTTP代码和JSON格式的缺失属性列表 目前,这个JSON响应只包含一个带有“errors”键的对象,该键存储一个错误消息数组。例如: {"errors":["'first_name' attribute is missing","'title' attribute is missing"]} 因此,API使用者只需检查“errors”键是否为null或是否

我正在构建一个JSON REST API。某些API操作需要属性。如果对这些操作发出的API请求没有所有必需的属性,API将返回4xx HTTP代码和JSON格式的缺失属性列表

目前,这个JSON响应只包含一个带有“errors”键的对象,该键存储一个错误消息数组。例如:

{"errors":["'first_name' attribute is missing","'title' attribute is missing"]}
因此,API使用者只需检查“errors”键是否为null或是否包含错误消息数组

你觉得这样够了吗?这是一个模糊的问题,我正在寻找报告此类错误的最佳/推荐做法,以使API的使用更加自然和简单