Home > Software design >  How can I parse the JSON response from Microsoft Graph Api List Chat into the textbox c# winform
How can I parse the JSON response from Microsoft Graph Api List Chat into the textbox c# winform

Time:10-19

This is the code what I have try base on my limitation knowledg it cannot display JSON Response of Microsoft.Graph API, it just appear the message box with the content of Microsoft.Graph.User.How can I parse the JsonResponse into the textbox. Documentation of ListChat In Correct Response

CodePudding user response:

You can try to deserialize it with Newtonsoft.Json

https://www.nuget.org/packages/Newtonsoft.Json/

To do that you need a class with the same properties as the .json file. So something like:

public class Response
{
    public List<Value> Values {get;set;}
}

public class Value
{
    public string Id {get;set;}
    public string Topic {get;set;
    .....
    public ChatViewPoint ChatViewPoint {get;set;}
}
public class ChatViewPoint
{
    public bool IsHidden {get;set;}
    ....
}

After you created the classes you can try to deserialize the string to the given datamodel.

Hope it works

CodePudding user response:

At

  var request = await graphClient.Me.Request().GetAsync();

you do not have JSON which you have to parse, but an object of type Microsoft.Graph.User. Since this object does not implement it's own .ToString() it gives you the result of the base implementation which is it's object type name.

If you want to display data of the user you have to access it's properties and display their values.

  • Related