When we use REST we get output as xml how do we parse this via JSOM and fetch the values?
Also, please provide some information on how to use this in SSOM instead of JSOM?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communityWhen we use REST we get output as xml how do we parse this via JSOM and fetch the values?
Also, please provide some information on how to use this in SSOM instead of JSOM?
The default format for SharePoint REST endpoint is application/atom+xml
. Instead of manipulating results returned in Xml
format you could specify JSON
format.
Use accept header
to specify the format for response data from the server. To get the results in JSON format, include an Accept header
set to application/json;odata=verbose
.
The code in the following example shows you how to request a JSON representation of all of the lists in a site by using
JavaScript:
$.ajax({
url: siteUrl + "/_api/web/lists",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
console.log(JSON.stringify(data.d.results));
},
error: function (data) {
console.log(JSON.stringify(data));
}
});
C#
var request = (HttpWebRequest)HttpWebRequest.Create(siteUrl + "/_api/web/lists");
request.Method = "GET";
request.Accept = "application/json;odata=verbose";
request.Headers.Add("Authorization", "Bearer " + accessToken);
var response = (HttpWebResponse)request.GetResponse();