简体   繁体   English

带有SharePoint Rest的Angular JS $ http解析响应

[英]Angular JS $http with SharePoint Rest Parsing the response

I am getting a very weird response while hitting sharepoint rest endpoint throught $http . 我通过$http到达sharepoint其余端点时得到一个非常奇怪的响应。

    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;
    }

Basically, I have built a angular factory that has all the function required to perform crud operations on sharepoint. 基本上,我建立了一个角度工厂,该工厂具有在共享点上执行粗体操作所需的所有功能。 I call the SPGet method to query a sharepoint list for list items. 我调用SPGet方法以查询SPGet列表中的列表项。 The call resolves successfully without error but I get a very weird output. 调用成功解决,没有错误,但输出非常奇怪。

"<?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="&quot;2&quot;"><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="&quot;2&quot;"><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="&quot;2&quot;"><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&amp;%24orderby=Severity+desc&amp;%24top=3&amp;%24select=Title%2cStatus%2cSeverity&amp;%24filter+Status+eq+%27Open%27+or+Status+eq+%27In+Progress%27=" /></feed>"

How do I parse this ? 我该如何解析? It seems to return the the expected items, but I am not sure how to parse it. 它似乎返回了预期的项目,但是我不确定如何解析它。

使用xml2json.js将输出转换为json,然后照常进行迭代

odata=nometadata is used for SharePoint online. odata=nometadata用于SharePoint Online。

If you are on prem you still want to use odata=verbose . 如果您正在使用Prem,则仍要使用odata=verbose

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

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