我正在使用服务来返回文件列表。此服务返回以下内容。
成功案例: json 格式的文件对象列表如下,HTTP 代码为 200
[{"_id:"3453534","name":"File 1"},{"_id:"5756753","name":"File 2"}]
失败案例:这将返回错误响应,错误消息为 HTTP 错误代码 500。
{errorMessage: "No files found for ptoject id 522b9358e4b0bab2f88a1f67"}
我正在使用以下“查询”方法调用此服务。
//get the new value of files as per changed project id
scope.files = ProjectFile.query({ projectid: scope.project._id }, function (response) {
//Check if service response is success/fail
if (response.servicestatus != undefined) {
//this is error case. Show error message.
alert("Failed to load list of files for this project: " + response.errorMessage);
}
else {
//update scope
scope.files = response;
}
});
我面临的问题是由 $query() 方法转换的响应对象。我收到的响应是一个看起来不正确的数组。不知道为什么 $query() 也期望错误响应作为数组。在错误情况下;我收到如下数组的响应
response[0][0]="N";
response[0][1]="o";
response[0][2]="";
response[0][3]="f";
response[0][4]="i";
response[0][5]="l";
response[0][6]="e";
response[0][7]="s";
....
....
我不确定为什么 $query() 会这样。不知道如何以正确的方式处理它。请帮忙。