這是我嘗試過的代碼。
根據我有限的知識,它無法顯示 Microsoft.Graph API 的 JSON 回應,它只是顯示帶有 Microsoft.Graph.User 內容的訊息框。
如何將 JsonResponse 決議到文本框中。
ListChat 的檔案:

uj5u.com熱心網友回復:
在
var request = await graphClient.Me.Request().GetAsync();
您沒有必須JSON決議的物件,而是型別的物件Microsoft.Graph.User。由于此物件沒有實作它自己的.ToString(),因此它為您提供了基本實作的結果,即它的物件型別名稱。
如果您真的需要物件 as JSON,您可以使用JSON像Newstonsoft提供的序列化程式,并使用它將您的資料序列化為JSON字串。
如果你想顯示用戶的資料,你必須訪問它的屬性并顯示它們的值。
uj5u.com熱心網友回復:
您可以使用on創建HttpRequestMessage、發送此訊息以獲取回應并閱讀內容。應該是json。HttpProviderGraphServiceClient
對于當前用戶
var httpMessage = graphClient.Me.Request().GetHttpRequestMessage();
var response = await graphClient.HttpProvider.SendAsync(httpMessage);
var jsonContent = await response.Content.ReadAsStringAsync();
MessageBox.Show(jsonContent);
用于聊天
var httpMessage = graphClient.Me.Chats.Request().GetHttpRequestMessage();
var response = await graphClient.HttpProvider.SendAsync(httpMessage);
var jsonContent = await response.Content.ReadAsStringAsync();
MessageBox.Show(jsonContent);
uj5u.com熱心網友回復:
您可以嘗試使用 Newtonsoft.Json 對其進行反序列化
https://www.nuget.org/packages/Newtonsoft.Json/
為此,您需要一個與 .json 檔案具有相同屬性的類。所以像:
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;}
....
}
創建類后,您可以嘗試將字串反序列化為給定的資料模型。
希望它有效
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/518543.html
標籤:C#json微软图形 API微软团队 js
上一篇:使用“正文”時,WordpressRESTAPI忽略來自GoogleApps腳本的POST請求
下一篇:將文本檔案轉換為json
