Hello,
If I try to fill my ObservableCollection based on my model, with the data from MS Graph then I get an error. So, I understand from Graph I get a Json stream(?) which is not compatible to my model. Is that correct so far?
If the response is in JSON format, you need to parse this JSON String, try to use NewtonSoft JSON.NET
library.
Right-click your project, select Manage Nuget Packages, search NewtonSoft
under Browse, install this package, then you could deserialize the JSON, refer to
var mscontacts = "{\"value\":[{\"parentFolderId\":\"parentFolderId-value\",\"birthday\":\"datetime-value\",\"fileAs\":\"fileAs-value\",\"displayName\":\"displayName-value\",\"givenName\":\"givenName-value\",\"initials\":\"initials-value\"}]}";
var mscontactsModel = JsonConvert.DeserializeObject<Mscontacts>(mscontacts);// I define a faker data to test
foreach (var mscontact in mscontactsModel.value)
{
Console.WriteLine("{0}", mscontact.initials);
}
The Model :
public class Mscontacts
{
public ObservableCollection<MscontactModel> value { get; set; }
}
public class MscontactModel
{
public string parentFolderId { get; set; }
public string birthday { get; set; }
public string fileAs { get; set; }
public string displayName { get; set; }
public string givenName { get; set; }
public string initials { get; set; }
}
You could refer to the Retrieve data part of this doc about How to Consume a RESTful web service: https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/web-services/rest#retrieve-data
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.