Search code examples
jsonodata

JSON object contains odata.Id how to get it out?


I used a sharepoint rest call which returned me an object with odata.id inside of it. But as javascript uses the . character as a delimeter for objects, I am clueless how I can select this attribute.

the object returned

Object
CheckInComment:""
CheckOutType:2
ContentTag:"{CF7867DB-4BF1-4013-BE2C-3ACA5839E5F4},1,2"
CustomizedPageStatus:0
ETag:""{CF7867DB-4BF1-4013-BE2C-3ACA5839E5F4},1""
Exists:true
IrmEnabled:false
Length:"254805"
Level:1
LinkingUri:null
LinkingUrl:""
MajorVersion:1
MinorVersion:0
Name:"nfs.jpg"
ServerRelativeUrl:"/sites/SiteDirectory/Banners/nfs.jpg"
TimeCreated:"2017-03-15T11:16:25Z"
TimeLastModified:"2017-03-15T11:16:25Z"
Title:null
UIVersion:512
UIVersionLabel:"1.0"
UniqueId:"cf7867db-4bf1-4013-be2c-3aca5839e5f4"
odata.editLink:"Web/GetFileByServerRelativeUrl'/sites/SiteDirectory/Banners/nfs.jpg')"
odata.id:"https://one365dev1.sharepoint.com/sites/SiteDirectory/_api/Web/GetFileByServerRelativeUrl('/sites/SiteDirectory/Banners/nfs.jpg')"
odata.type:"SP.File"odata.id:"https://one365dev1.sharepoint.com/sites/SiteDirectory/_api/Web/GetFileByServerRelativeUrl('/sites/SiteDirectory/Banners/nfs.jpg')"
    odata.type:"SP.File"

my code to get the object

$http.get(endpoint).then(function (result) {
    var banners = result.data;
    deferred.resolve(banners);
    console.log(banners.Files[0]);
});

but since I cannot do

console.log(banners.Files[0].odata.id);

the post return by fiddler:

enter image description here

I am clueless of how to access the data. any help will be appreciated.

thanks


Solution

  • The name of the object is odata.id and not id in odata.

    That's why you need to acccess it in the bracket notation: banners.Files[0]['odata.id'].