Reputation: 174
I am having a problem extracting the "Id" property from the following JSON result using RestSharp: **Here is the JSON*:
{
"odata.metadata":"Api/v1/$metadata#Folders","odata.count":"1","value":
[
{
"odata.id":"/Api/v1/Folders('c8644e97b4ca4353b5bd74a0cc37588214')","[email protected]":"/Api/v1/Folders('c8644e97b4ca4353b5bd74a0cc37588214')/Presentations","#UpdatePermissions":
{
"target":"Api/v1/Folders('c8644e97b4ca4353b5bd74a0cc37588214')/UpdatePermissions"
}
,"Id":"c8644e97b4ca4353b5bd74a0cc37588214","Name":"2013-AAFGSW","Owner":"John Doe","Description":"EPIDEM 150.03, Summer 2013","CreationDate":"2014-06-09T22:00:43","LastModified":"2014-06-09T22:00:43","ParentFolderId":"2f5469c7bdf641878c8baf2988ceeb9a14","Recycled":false,"Type":"Folder"
}
]
}
Here are my classes that I am using:
public class Value
{
public string Id { get; set; }
public string Name { get; set; }
public string Owner { get; set; }
public string Description { get; set; }
public string CreationDate { get; set; }
public string LastModified { get; set; }
public string ParentFolderId { get; set; }
public bool Recycled { get; set; }
public string Type { get; set; }
}
public class FolderRoot <T>
{
public List<Value> value { get; set; }
}
Here is the request code:
var BuildFolderIdRequest = new RestRequest(Method.GET);
BuildFolderIdRequest.Resource = string.Format("Folders?$filter=Name eq '{0}'",x.event_locator);
BuildFolderIdRequest.RequestFormat = DataFormat.Json;
BuildFolderIdRequest.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };
BuildFolderIdRequest.AddHeader("apikey", ApiKey);
var Fold = MediasiteClient.Execute<FolderRoot<Value>>(BuildFolderIdRequest);
Console.WriteLine("The folder content is {0}", Fold.Content);
Console.WriteLine("The folder Id is {0}", Fold.Data.????);
Console.ReadKey();
The problem is trying to extract the "Id" -- as I can't do it with "Fold.Data.Id" , instead i just get "Fold.Data.value" as my only option...
Upvotes: 0
Views: 1103
Reputation: 323
Looks like you're using MediaSite's new v7 REST API. Try the following just before executing your request:
BuildFolderIdRequest.RootElement = "value";
If you look at the raw JSON results you were already receiving with Fold.Content
you should see that the results you want are under the node called value
. Without that mapping, deserialization might not work. Best of luck.
Upvotes: 1
Reputation: 173
I think you need to select an element of your list before you can get an ID from it, like
Fold.Data[0].Id
Does that work? I am not overly familiar with de-serialization, but that's what it looks like to me.
Is the type of "Folder.Data.value" a list?
Upvotes: 0