简体   繁体   中英

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:

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. Please Help.

Pelase help me in converting usersForDep to json data.

When you "deserialize" and object, you are converting a JSON string into an object. To convert an object into a JSON string, you to "serialize" that object.

Beyond that, usersForDep is not a JSON response. It is already a C# object ( GraphServiceUsersCollectionPage ). The SDK handles serialization and deserialization automatically.

One important note, usersForDep.ToString() won't serialize an object into JSON. It will simply return the string representation of an object; which in this case would be usersForDep 's Type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM