Angular JS $http with SharePoint Rest 解析响应
Angular JS $http with SharePoint Rest Parsing the response
我在通过 $http
访问共享点休息端点时收到一个非常奇怪的响应。
var _get = function($scope) {
var lName = $scope.wp.lName;
var filter = $scope.wp.filter;
var url = $scope.wp.url;
var differed = $q.defer();
var tUrl = <url>
$http({
method:'GET',
url:tUrl,
headers: { "Accept": "application/json; odata=nometadata" }
})
.then(
function (data) {
$scope.alert = data.data.value;
differed.resolve($scope.alert);
},
function (data, status, headers, config) {
console.log(data);
});
return differed.promise;
}
基本上,我已经建立了一个 angular 工厂,它具有在 sharepoint 上执行 crud 操作所需的所有功能。我调用 SPGet
方法来查询列表项的共享点列表。调用成功解析,没有错误,但我得到了一个非常奇怪的输出。
"<?xml version="1.0" encoding="utf-8"?><feed xml:base="<base>" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>b8b4ee0c-a5ce-4ef0-92ec-b529ccdc2997</id><title /><updated>2015-06-23T14:26:58Z</updated><entry m:etag=""2""><id>Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(2)</id><category term="SP.Data.SystemAlertListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(2)" /><title /><updated>2015-06-23T14:26:58Z</updated><author><name /></author><content type="application/xml"><m:properties><d:Title>Test B</d:Title><d:Status>In Progress</d:Status><d:Severity>Med</d:Severity></m:properties></content></entry><entry m:etag=""2""><id>Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(3)</id><category term="SP.Data.SystemAlertListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(3)" /><title /><updated>2015-06-23T14:26:58Z</updated><author><name /></author><content type="application/xml"><m:properties><d:Title>Test C</d:Title><d:Status>Open</d:Status><d:Severity>Low</d:Severity></m:properties></content></entry><entry m:etag=""2""><id>Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(4)</id><category term="SP.Data.SystemAlertListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(4)" /><title /><updated>2015-06-23T14:26:58Z</updated><author><name /></author><content type="application/xml"><m:properties><d:Title>Test D</d:Title><d:Status>Closed</d:Status><d:Severity>High</d:Severity></m:properties></content></entry><link rel="next" href="http://intersys-tc3:8000/sites/SA/_api/web/lists/GetByTitle('SystemAlert')/items?%24skiptoken=Paged%3dTRUE%26p_Severity%3dHigh%26p_ID%3d4&%24orderby=Severity+desc&%24top=3&%24select=Title%2cStatus%2cSeverity&%24filter+Status+eq+%27Open%27+or+Status+eq+%27In+Progress%27=" /></feed>"
我该如何解析这个?似乎 return 是预期的项目,但我不确定如何解析它。
使用xml2json.js将输出转换为json,然后照常迭代
odata=nometadata
用于在线 SharePoint。
如果您在 prem 上,您仍想使用 odata=verbose
。
我在通过 $http
访问共享点休息端点时收到一个非常奇怪的响应。
var _get = function($scope) {
var lName = $scope.wp.lName;
var filter = $scope.wp.filter;
var url = $scope.wp.url;
var differed = $q.defer();
var tUrl = <url>
$http({
method:'GET',
url:tUrl,
headers: { "Accept": "application/json; odata=nometadata" }
})
.then(
function (data) {
$scope.alert = data.data.value;
differed.resolve($scope.alert);
},
function (data, status, headers, config) {
console.log(data);
});
return differed.promise;
}
基本上,我已经建立了一个 angular 工厂,它具有在 sharepoint 上执行 crud 操作所需的所有功能。我调用 SPGet
方法来查询列表项的共享点列表。调用成功解析,没有错误,但我得到了一个非常奇怪的输出。
"<?xml version="1.0" encoding="utf-8"?><feed xml:base="<base>" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>b8b4ee0c-a5ce-4ef0-92ec-b529ccdc2997</id><title /><updated>2015-06-23T14:26:58Z</updated><entry m:etag=""2""><id>Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(2)</id><category term="SP.Data.SystemAlertListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(2)" /><title /><updated>2015-06-23T14:26:58Z</updated><author><name /></author><content type="application/xml"><m:properties><d:Title>Test B</d:Title><d:Status>In Progress</d:Status><d:Severity>Med</d:Severity></m:properties></content></entry><entry m:etag=""2""><id>Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(3)</id><category term="SP.Data.SystemAlertListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(3)" /><title /><updated>2015-06-23T14:26:58Z</updated><author><name /></author><content type="application/xml"><m:properties><d:Title>Test C</d:Title><d:Status>Open</d:Status><d:Severity>Low</d:Severity></m:properties></content></entry><entry m:etag=""2""><id>Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(4)</id><category term="SP.Data.SystemAlertListItem" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/Lists(guid'81419977-601f-46bd-aee5-8e6ebbb34b48')/Items(4)" /><title /><updated>2015-06-23T14:26:58Z</updated><author><name /></author><content type="application/xml"><m:properties><d:Title>Test D</d:Title><d:Status>Closed</d:Status><d:Severity>High</d:Severity></m:properties></content></entry><link rel="next" href="http://intersys-tc3:8000/sites/SA/_api/web/lists/GetByTitle('SystemAlert')/items?%24skiptoken=Paged%3dTRUE%26p_Severity%3dHigh%26p_ID%3d4&%24orderby=Severity+desc&%24top=3&%24select=Title%2cStatus%2cSeverity&%24filter+Status+eq+%27Open%27+or+Status+eq+%27In+Progress%27=" /></feed>"
我该如何解析这个?似乎 return 是预期的项目,但我不确定如何解析它。
使用xml2json.js将输出转换为json,然后照常迭代
odata=nometadata
用于在线 SharePoint。
如果您在 prem 上,您仍想使用 odata=verbose
。