在 UWP 中 JSON 反序列化后计算的 Sharepoint 值 Returns 为空

Calculated Sharepoint Value Returns Null after JSON Deserialize in UWP

所以我正在尝试 return 来自共享点列表的几个 ListItems。我很好地恢复了内容,但是当它反序列化内容时,计算出的列 return 是一个空值。我只是不明白,因为内容中有价值。

string geturl = "https://graph.microsoft.com/v1.0/sites/XXXXX.sharepoint.com,495435b4-60c3-49b7-8f6e-1d262a120ae5,0fad9f67-35a8-4c0b-892e-113084058c0a/lists/18a725ac-83ef-48fb-a5cb-950ca2378fd0/items/9?expand=fields(select=SerialNumber,id)";        

public async Task<string> GetDataWithTokenAsync(string url, string token, string listitem)
        {
            var httpClient = new System.Net.Http.HttpClient();
            System.Net.Http.HttpResponseMessage response;
            try
            {
                var request = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, url);
                //Add the token in Authorization header
                request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", token);
                response = await httpClient.SendAsync(request);
                var content = await response.Content.ReadAsStringAsync();
                var result = JsonConvert.DeserializeObject<SharePointListItems.RootObject>(content);
                if (listitem == "id")
                {
                    return result.fields.Id;
                }
                else
                {
                    return result.fields.SerialNumber;
                }
            }
            catch (Exception ex)
            {
                return ex.ToString();
            }
        }

这里是class(缩写):

public class SharePointListItems
{
    public class Fields
    {
        [JsonProperty("@odata.etag")]
        public string ODataETag { get; set; }

        //General Parameters
        ...
        public string SerialNumber { get; set; } // Calculated field in Sharepoint
        public string Id { get; set; }

        ...
    }

    public class RootObject
    {
        [JsonProperty("@odata.context")]
        public string ODataContext { get; set; }

        [JsonProperty("@odata.etag")]
        public string ODataETag { get; set; }

        [JsonProperty("fields@odata.context")]
        public string FieldsODataContext { get; set; }

        public Fields fields { get; set; }
    }
}

用我的 GET return编辑的内容是:

"{\"@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#sites('XXXXX.sharepoint.com%2C495435b4-60c3-49b7-8f6e-1d262a120ae5%2C0fad9f67-35a8-4c0b-892e-113084058c0a')/lists('18a725ac-83ef-48fb-a5cb-950ca2378fd0')/items/$entity\",\"@odata.etag\":\"\\"a69b1840-239d-42ed-9b20-8789761fb06a,3\\"\",\"createdDateTime\":\"2018-08-25T22:44:16Z\",\"eTag\":\"\\"a69b1840-239d-42ed-9b20-8789761fb06a,3\\"\",\"id\":\"9\",\"lastModifiedDateTime\":\"2018-08-25T22:44:16Z\",\"webUrl\":\"https://XXXXX.sharepoint.com/sites/GeneratorApp/Lists/GenApp/9_.000\",\"createdBy\":{\"user\":{\"email\":\"XXXXX@XXXXX.com\",\"id\":\"b0465821-e891-4f44-9e18-27e875f1b75d\",\"displayName\":\"XXXXX\"}},\"lastModifiedBy\":{\"user\":{\"email\":\"XXXXX@XXXXX.com\",\"id\":\"b0465821-e891-4f44-9e18-27e875f1b75d\",\"displayName\":\"XXXXX\"}},\"parentReference\":{},\"contentType\":{\"id\":\"0x0100E19591A4ECA81542AEA41A6AAFED6781\"},\"fields@odata.context\":\"https://graph.microsoft.com/v1.0/$metadata#sites('XXXXX.sharepoint.com%2C495435b4-60c3-49b7-8f6e-1d262a120ae5%2C0fad9f67-35a8-4c0b-892e-113084058c0a')/lists('18a725ac-83ef-48fb-a5cb-950ca2378fd0')/items('9')/fields/$entity\",\"fields\":{\"@odata.etag\":\"\\"a69b1840-239d-42ed-9b20-8789761fb06a,3\\"\",\"SerialNumber\":\"20180824-1353-DC6-Generator-A\",\"id\":\"9\"}}"

如果我加一行

Jobject json = Jobject.Parse(content);

我得到以下响应(更改端点以获取多个 ListItems):

{{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('XXXXX.sharepoint.com%2C495435b4-60c3-49b7-8f6e-1d262a120ae5%2C0fad9f67-35a8-4c0b-892e-113084058c0a')/lists('18a725ac-83ef-48fb-a5cb-950ca2378fd0')/items",
  "value": [
    {
      "@odata.etag": "\"a69b1840-239d-42ed-9b20-8789761fb06a,3\"",
      "createdDateTime": "2018-08-25T22:44:16Z",
      "eTag": "\"a69b1840-239d-42ed-9b20-8789761fb06a,3\"",
      "id": "9",
      "lastModifiedDateTime": "2018-08-25T22:44:16Z",
      "webUrl": "https://XXXXX.sharepoint.com/sites/GeneratorApp/Lists/GenApp/9_.000",
      "createdBy": {
        "user": {
          "email": "XXXXX@XXXXX.com",
          "id": "b0465821-e891-4f44-9e18-27e875f1b75d",
          "displayName": "XXXXX"
        }
      },
      "lastModifiedBy": {
        "user": {
          "email": "XXXXX@XXXXX.com",
          "id": "b0465821-e891-4f44-9e18-27e875f1b75d",
          "displayName": "XXXXX"
        }
      },
      "parentReference": {},
      "contentType": {
        "id": "0x0100E19591A4ECA81542AEA41A6AAFED6781"
      },
      "fields@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('XXXXX.sharepoint.com%2C495435b4-60c3-49b7-8f6e-1d262a120ae5%2C0fad9f67-35a8-4c0b-892e-113084058c0a')/lists('18a725ac-83ef-48fb-a5cb-950ca2378fd0')/items('9')/fields/$entity",
      "fields": {
        "@odata.etag": "\"a69b1840-239d-42ed-9b20-8789761fb06a,3\"",
        "SerialNumber": "20180824-1353-DC6-Generator-A",
        "id": "9"
      }
    },
    {
      "@odata.etag": "\"13f60f9e-1bf2-4803-93b9-c45234963d47,3\"",
      "createdDateTime": "2018-08-25T22:45:55Z",
      "eTag": "\"13f60f9e-1bf2-4803-93b9-c45234963d47,3\"",
      "id": "10",
      "lastModifiedDateTime": "2018-08-25T22:45:55Z",
      "webUrl": "https://XXXXX.sharepoint.com/sites/GeneratorApp/Lists/GenApp/10_.000",
      "createdBy": {
        "user": {
          "email": "XXXXX@XXXXX.com",
          "id": "b0465821-e891-4f44-9e18-27e875f1b75d",
          "displayName": "XXXXX"
        }
      },
      "lastModifiedBy": {
        "user": {
          "email": "XXXXX@XXXXX.com",
          "id": "b0465821-e891-4f44-9e18-27e875f1b75d",
          "displayName": "XXXXX"
        }
      },
      "parentReference": {},
      "contentType": {
        "id": "0x0100E19591A4ECA81542AEA41A6AAFED6781"
      },
      "fields@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('XXXXX.sharepoint.com%2C495435b4-60c3-49b7-8f6e-1d262a120ae5%2C0fad9f67-35a8-4c0b-892e-113084058c0a')/lists('18a725ac-83ef-48fb-a5cb-950ca2378fd0')/items('10')/fields/$entity",
      "fields": {
        "@odata.etag": "\"13f60f9e-1bf2-4803-93b9-c45234963d47,3\"",
        "SerialNumber": "20180824-1416-DC6-Generator-B",
        "id": "10"
      }
    },
    {
      "@odata.etag": "\"00024848-0d4e-4ee8-b018-f1653af2a577,3\"",
      "createdDateTime": "2018-08-25T22:47:30Z",
      "eTag": "\"00024848-0d4e-4ee8-b018-f1653af2a577,3\"",
      "id": "11",
      "lastModifiedDateTime": "2018-08-25T22:47:30Z",
      "webUrl": "https://XXXXX.sharepoint.com/sites/GeneratorApp/Lists/GenApp/11_.000",
      "createdBy": {
        "user": {
          "email": "XXXXX@XXXXX.com",
          "id": "b0465821-e891-4f44-9e18-27e875f1b75d",
          "displayName": "XXXXX"
        }
      },
      "lastModifiedBy": {
        "user": {
          "email": "XXXXX@XXXXX.com",
          "id": "b0465821-e891-4f44-9e18-27e875f1b75d",
          "displayName": "XXXXX"
        }
      },
      "parentReference": {},
      "contentType": {
        "id": "0x0100E19591A4ECA81542AEA41A6AAFED6781"
      },
      "fields@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('XXXXX.sharepoint.com%2C495435b4-60c3-49b7-8f6e-1d262a120ae5%2C0fad9f67-35a8-4c0b-892e-113084058c0a')/lists('18a725ac-83ef-48fb-a5cb-950ca2378fd0')/items('11')/fields/$entity",
      "fields": {
        "@odata.etag": "\"00024848-0d4e-4ee8-b018-f1653af2a577,3\"",
        "SerialNumber": "20180824-1438-DC6-Generator-R",
        "id": "11"
      }
    },
    {
      "@odata.etag": "\"7c8e80ed-6fea-408a-9594-2b7b13e3691b,3\"",
      "createdDateTime": "2018-08-25T23:02:43Z",
      "eTag": "\"7c8e80ed-6fea-408a-9594-2b7b13e3691b,3\"",
      "id": "12",
      "lastModifiedDateTime": "2018-08-25T23:02:43Z",
      "webUrl": "https://XXXXX.sharepoint.com/sites/GeneratorApp/Lists/GenApp/12_.000",
      "createdBy": {
        "user": {
          "email": "XXXXX@XXXXX.com",
          "id": "b0465821-e891-4f44-9e18-27e875f1b75d",
          "displayName": "XXXXX"
        }
      },
      "lastModifiedBy": {
        "user": {
          "email": "XXXXX@XXXXX.com",
          "id": "b0465821-e891-4f44-9e18-27e875f1b75d",
          "displayName": "XXXXX"
        }
      },
      "parentReference": {},
      "contentType": {
        "id": "0x0100E19591A4ECA81542AEA41A6AAFED6781"
      },
      "fields@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites('XXXXX.sharepoint.com%2C495435b4-60c3-49b7-8f6e-1d262a120ae5%2C0fad9f67-35a8-4c0b-892e-113084058c0a')/lists('18a725ac-83ef-48fb-a5cb-950ca2378fd0')/items('12')/fields/$entity",
      "fields": {
        "@odata.etag": "\"7c8e80ed-6fea-408a-9594-2b7b13e3691b,3\"",
        "SerialNumber": "20180824-1456-DC6-Generator-C",
        "id": "12"
      }
    }
  ]
}}

我现在好像在兜圈子

我想要结束的是一个 id 和 SerialNumber 的列表。

[代码已更新以反映我的评论]

因为我真的回答了主题的问题,所以我问的第二件事是一个完全不同的问题。

原来我看错了数据。在我正在查看的区域中碰巧也有一个 'id' 字段,所以它显示 'id' 而不是我真正要找的那个。当我设置适当的入口点时,我能够深入到适当的领域。