Domanda

I am getting a list stored in sharepoint 2013 using rest api successfully. On the client side i want to iterate through the object. Can anybody tell me how the data is structured.

È stato utile?

Soluzione

Iterate through each list item as follows:

 function (data) 
    {  
      if (data.d != undefined)
      {
      //Check if the list has data
      if (data.d.results.length > 0)
      {       
      //Iterate through each items fetched from the list
     $.each(data.d.results, function(index, item)
       {

        var fieldVal= item.fieldName;
});
}
}
}   

You can see the response format in the browser for your list by using the following url:

site url + /_api/web/lists/getbytitle('listname')/items

Refer the following url for more info: http://sergeluca.wordpress.com/2013/01/20/sharepoint-2013-rest-odata-part-1-readingfetching-information-no-code/

Altri suggerimenti

It can be either XML or JSON.

See

http://msdn.microsoft.com/en-us/library/office/jj164022.aspx

The following code demonstrates how this request would look if you are using the cross-domain library and want to receive the OData representation of the lists as XML instead of JSON. See How to: Access SharePoint 2013 data from apps using the cross-domain library for more information about using the cross-domain library.

HttpWebRequest endpointRequest = (HttpWebRequest)HttpWebRequest.Create(sharepointUrl.ToString() + "/_api/web/lists");
endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
endpointRequest.Headers.Add("Authorization", "Bearer " + accessToken);
HttpWebResponse endpointResponse = (HttpWebResponse)endpointRequest.GetResponse();
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top