[英]Issue in Converting the Users Results from Microsoft Graph API V1.0 to Json
I am using below code to get all users and then converting it to Json Data:我使用以下代码获取所有用户,然后将其转换为 Json 数据:
var usersForDep = await graphServiceClient1.Users.Request().Select(e => new
{
e.Department,
e.BusinessPhones,
e.MobilePhone
}).GetAsync();
JObject json = (JObject)JsonConvert.DeserializeObject(usersForDep.ToString());
usersForDep is of Microsoft.Graph.Users type which has several fields like Job Title, Email, Contact. usersForDep 是 Microsoft.Graph.Users 类型,它有几个字段,如职位、电子邮件、联系人。 Please Help.请帮忙。
Pelase help me in converting usersForDep to json data. Pelase 帮助我将 usersForDep 转换为 json 数据。
When you "deserialize" and object, you are converting a JSON string into an object.当您“反序列化”和对象时,您正在将 JSON 字符串转换为对象。 To convert an object into a JSON string, you to "serialize" that object.要将对象转换为 JSON 字符串,您需要“序列化”该对象。
Beyond that, usersForDep
is not a JSON response.除此之外, usersForDep
不是 JSON 响应。 It is already a C# object ( GraphServiceUsersCollectionPage
).它已经是一个 C# 对象 ( GraphServiceUsersCollectionPage
)。 The SDK handles serialization and deserialization automatically. SDK 自动处理序列化和反序列化。
One important note, usersForDep.ToString()
won't serialize an object into JSON.一个重要的注意事项, usersForDep.ToString()
不会将对象序列化为 JSON。 It will simply return the string representation of an object;它将简单地返回一个对象的字符串表示; which in this case would be usersForDep
's Type.在这种情况下,这将是usersForDep
的类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.