我对编程很陌生,特别是Microsoft.Graph
我在处理响应时遇到问题: https://graph.microsoft.com/v1.0/me/drive/root/children
响应看起来像这样(只是更长):
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('xyz%40hotmail.com')/drive/root/children",
"value": [
{
"createdBy": {
"user": {
"displayName": "xyz",
"id": "cf58e4781082"
}
},
"createdDateTime": "2009-01-08T08:52:07.063Z",
"cTag": "adDpFREJDR4RTQMTgxMDgyITEyOC42MzYxODM0MTU0Mjc3MDAwMDA",
"eTag": "aRURCQ0Y1OEU0A4MiExMjguMA",
"id": "EDBCF58E471082!128",
"lastModifiedBy": {
"user": {
"displayName": "xyz",
"id": "edbcf58e48082"
}
}, ............. etc...
我收到的回复是正确的,采用JSON格式(我相信><),但我无法弄清楚如何将其解析为包含文件夹名称的数组。
请帮忙!
答案 0 :(得分:0)
您可以使用 JavaScriptSerializer
执行此操作。假设
//json contains the JSON Response
var jsonOutput = new System.Web.Script.Serialization.JavaScriptSerializer();
jsonOutput.DeserializeObject(json);
这已在前面讨论过。请参阅此主题:Easiest way to parse JSON response
请参阅此链接以获取 JavaScriptSerializer :https://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer(v=vs.110).aspx
答案 1 :(得分:0)
是否考虑过使用Microsoft Graph client library?它将反序列化JSON。您的电话将如下所示:
// Return all children files and folders off the drive root.
var driveItems = await graphClient.Me.Drive
.Root
.Children
.Request()
.GetAsync();
foreach (var item in driveItems)
{
// Get your item information
}
以下是帮助您入门的一些示例: https://github.com/microsoftgraph?utf8=%E2%9C%93&q=csharp