ConvertFrom-Json : Cannot convert the JSON string

2019-04-09 10:31发布

问题:

The following JSON is returned from SharePoint REST service:

{
  "d": {
    "results": [
      {
        "__metadata": {
          "id": "c7b44ed8-a1fc-44cb-ab36-46aacf1ff992",
          "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)",
          "etag": "\"1\"",
          "type": "SP.Data.Nokia_x0020_OfficesListItem"
        },
        "FirstUniqueAncestorSecurableObject": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/FirstUniqueAncestorSecurableObject"
          }
        },
        "RoleAssignments": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/RoleAssignments"
          }
        },
        "AttachmentFiles": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/AttachmentFiles"
          }
        },
        "ContentType": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/ContentType"
          }
        },
        "FieldValuesAsHtml": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/FieldValuesAsHtml"
          }
        },
        "FieldValuesAsText": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/FieldValuesAsText"
          }
        },
        "FieldValuesForEdit": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/FieldValuesForEdit"
          }
        },
        "File": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/File"
          }
        },
        "Folder": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/Folder"
          }
        },
        "ParentList": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(1)\/ParentList"
          }
        },
        "FileSystemObjectType": 0,
        "Id": 1,
        "ContentTypeId": "0x0100BC97B2F575CB0C42B79549F3BABD32A8",
        "Title": "Nokia California",
        "Address": "200 South Matilda Avenue\nW Washington Ave\n94086 Sunnyvale, California\nUnited States of America",
        "ID": 1,
        "Modified": "2014-02-24T10:06:39Z",
        "Created": "2014-02-24T10:06:39Z",
        "AuthorId": 12,
        "EditorId": 12,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "d12aafad-502a-4968-a69e-36a7ea05ec80"
      },
      {
        "__metadata": {
          "id": "9cc23c9f-5ed3-4717-9e22-9b0ca4d09e05",
          "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)",
          "etag": "\"1\"",
          "type": "SP.Data.Nokia_x0020_OfficesListItem"
        },
        "FirstUniqueAncestorSecurableObject": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/FirstUniqueAncestorSecurableObject"
          }
        },
        "RoleAssignments": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/RoleAssignments"
          }
        },
        "AttachmentFiles": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/AttachmentFiles"
          }
        },
        "ContentType": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/ContentType"
          }
        },
        "FieldValuesAsHtml": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/FieldValuesAsHtml"
          }
        },
        "FieldValuesAsText": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/FieldValuesAsText"
          }
        },
        "FieldValuesForEdit": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/FieldValuesForEdit"
          }
        },
        "File": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/File"
          }
        },
        "Folder": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/Folder"
          }
        },
        "ParentList": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(2)\/ParentList"
          }
        },
        "FileSystemObjectType": 0,
        "Id": 2,
        "ContentTypeId": "0x0100BC97B2F575CB0C42B79549F3BABD32A8",
        "Title": "Nokia Eurasia",
        "Address": "Leningradskoe shosse 16a, building 2\n\u041b\u0435\u043d\u0438\u043d\u0433\u0440\u0430\u0434\u0441\u043a\u043e\u0435 \u0448\u043e\u0441\u0441\u0435, 16\u0430, \u0441\u0442\u0440\u043e\u0435\u043d\u0438\u0435 2\nRUSSIA",
        "ID": 2,
        "Modified": "2014-02-24T10:07:16Z",
        "Created": "2014-02-24T10:07:16Z",
        "AuthorId": 12,
        "EditorId": 12,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "5aef210c-5590-4633-83b7-3f56902da0ca"
      },
      {
        "__metadata": {
          "id": "8366fe34-3a9c-40cc-b62f-08c02f06ae0a",
          "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)",
          "etag": "\"1\"",
          "type": "SP.Data.Nokia_x0020_OfficesListItem"
        },
        "FirstUniqueAncestorSecurableObject": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/FirstUniqueAncestorSecurableObject"
          }
        },
        "RoleAssignments": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/RoleAssignments"
          }
        },
        "AttachmentFiles": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/AttachmentFiles"
          }
        },
        "ContentType": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/ContentType"
          }
        },
        "FieldValuesAsHtml": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/FieldValuesAsHtml"
          }
        },
        "FieldValuesAsText": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/FieldValuesAsText"
          }
        },
        "FieldValuesForEdit": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/FieldValuesForEdit"
          }
        },
        "File": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/File"
          }
        },
        "Folder": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/Folder"
          }
        },
        "ParentList": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(3)\/ParentList"
          }
        },
        "FileSystemObjectType": 0,
        "Id": 3,
        "ContentTypeId": "0x0100BC97B2F575CB0C42B79549F3BABD32A8",
        "Title": "Nokia Latin America",
        "Address": "703 NW 62nd Av, Suite 100\nMiami FL, 33126\nUSA",
        "ID": 3,
        "Modified": "2014-02-24T10:07:53Z",
        "Created": "2014-02-24T10:07:53Z",
        "AuthorId": 12,
        "EditorId": 12,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "c4e9b03b-1869-423a-9df0-100928020f58"
      },
      {
        "__metadata": {
          "id": "aa638997-e55c-4389-9353-ce6911d62441",
          "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)",
          "etag": "\"1\"",
          "type": "SP.Data.Nokia_x0020_OfficesListItem"
        },
        "FirstUniqueAncestorSecurableObject": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/FirstUniqueAncestorSecurableObject"
          }
        },
        "RoleAssignments": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/RoleAssignments"
          }
        },
        "AttachmentFiles": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/AttachmentFiles"
          }
        },
        "ContentType": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/ContentType"
          }
        },
        "FieldValuesAsHtml": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/FieldValuesAsHtml"
          }
        },
        "FieldValuesAsText": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/FieldValuesAsText"
          }
        },
        "FieldValuesForEdit": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/FieldValuesForEdit"
          }
        },
        "File": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/File"
          }
        },
        "Folder": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/Folder"
          }
        },
        "ParentList": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(4)\/ParentList"
          }
        },
        "FileSystemObjectType": 0,
        "Id": 4,
        "ContentTypeId": "0x0100BC97B2F575CB0C42B79549F3BABD32A8",
        "Title": "Nokia Brazil",
        "Address": "Av das Nacoes Unidas\n12.901 Torre Norte 11o.\nSao Paulo 04578-910\nBRAZIL",
        "ID": 4,
        "Modified": "2014-02-24T10:08:22Z",
        "Created": "2014-02-24T10:08:22Z",
        "AuthorId": 12,
        "EditorId": 12,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "e8525c17-f92c-4b3a-8947-70a8dfd74105"
      },
      {
        "__metadata": {
          "id": "32bfc6af-8e16-4956-ab1b-786868ee6225",
          "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)",
          "etag": "\"1\"",
          "type": "SP.Data.Nokia_x0020_OfficesListItem"
        },
        "FirstUniqueAncestorSecurableObject": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/FirstUniqueAncestorSecurableObject"
          }
        },
        "RoleAssignments": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/RoleAssignments"
          }
        },
        "AttachmentFiles": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/AttachmentFiles"
          }
        },
        "ContentType": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/ContentType"
          }
        },
        "FieldValuesAsHtml": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/FieldValuesAsHtml"
          }
        },
        "FieldValuesAsText": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/FieldValuesAsText"
          }
        },
        "FieldValuesForEdit": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/FieldValuesForEdit"
          }
        },
        "File": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/File"
          }
        },
        "Folder": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/Folder"
          }
        },
        "ParentList": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(5)\/ParentList"
          }
        },
        "FileSystemObjectType": 0,
        "Id": 5,
        "ContentTypeId": "0x0100BC97B2F575CB0C42B79549F3BABD32A8",
        "Title": "Nokia Greater China & Korea",
        "Address": "Beijing Economic and Technological Development Area\nNo.5 Donghuan Zhonglu\nBeijing, PRC 100176",
        "ID": 5,
        "Modified": "2014-02-24T10:08:54Z",
        "Created": "2014-02-24T10:08:54Z",
        "AuthorId": 12,
        "EditorId": 12,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "f1036544-6baf-44a7-9613-fba94edcb18e"
      },
      {
        "__metadata": {
          "id": "a53f51b3-fb65-429d-97e9-a175a2111e59",
          "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)",
          "etag": "\"1\"",
          "type": "SP.Data.Nokia_x0020_OfficesListItem"
        },
        "FirstUniqueAncestorSecurableObject": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/FirstUniqueAncestorSecurableObject"
          }
        },
        "RoleAssignments": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/RoleAssignments"
          }
        },
        "AttachmentFiles": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/AttachmentFiles"
          }
        },
        "ContentType": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/ContentType"
          }
        },
        "FieldValuesAsHtml": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/FieldValuesAsHtml"
          }
        },
        "FieldValuesAsText": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/FieldValuesAsText"
          }
        },
        "FieldValuesForEdit": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/FieldValuesForEdit"
          }
        },
        "File": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/File"
          }
        },
        "Folder": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/Folder"
          }
        },
        "ParentList": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(6)\/ParentList"
          }
        },
        "FileSystemObjectType": 0,
        "Id": 6,
        "ContentTypeId": "0x0100BC97B2F575CB0C42B79549F3BABD32A8",
        "Title": "Nokia South East Asia and Pacific",
        "Address": "Gateway East\n152 Beach Road\n#20-01\/08\nSingapore 189721",
        "ID": 6,
        "Modified": "2014-02-24T10:09:30Z",
        "Created": "2014-02-24T10:09:30Z",
        "AuthorId": 12,
        "EditorId": 12,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "70a6be95-ecfc-45b9-82cd-5a874f4482ae"
      },
      {
        "__metadata": {
          "id": "cb2a7a1a-fc2c-409c-a712-6cfa0b7253c8",
          "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)",
          "etag": "\"1\"",
          "type": "SP.Data.Nokia_x0020_OfficesListItem"
        },
        "FirstUniqueAncestorSecurableObject": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/FirstUniqueAncestorSecurableObject"
          }
        },
        "RoleAssignments": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/RoleAssignments"
          }
        },
        "AttachmentFiles": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/AttachmentFiles"
          }
        },
        "ContentType": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/ContentType"
          }
        },
        "FieldValuesAsHtml": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/FieldValuesAsHtml"
          }
        },
        "FieldValuesAsText": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/FieldValuesAsText"
          }
        },
        "FieldValuesForEdit": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/FieldValuesForEdit"
          }
        },
        "File": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/File"
          }
        },
        "Folder": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/Folder"
          }
        },
        "ParentList": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(7)\/ParentList"
          }
        },
        "FileSystemObjectType": 0,
        "Id": 7,
        "ContentTypeId": "0x0100BC97B2F575CB0C42B79549F3BABD32A8",
        "Title": "Nokia India",
        "Address": "SP Infocity,\nIndustrial Plot no. 243\nUdyog Vihar, Phase 1,\nDundahera, Gurgaon,\nHaryana - 122016.\nINDIA",
        "ID": 7,
        "Modified": "2014-02-24T10:10:20Z",
        "Created": "2014-02-24T10:10:20Z",
        "AuthorId": 12,
        "EditorId": 12,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "24499aae-7659-410f-acd8-899404bbddc8"
      },
      {
        "__metadata": {
          "id": "824dc9e9-d958-473b-bde1-4c4e3a48604b",
          "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)",
          "etag": "\"1\"",
          "type": "SP.Data.Nokia_x0020_OfficesListItem"
        },
        "FirstUniqueAncestorSecurableObject": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/FirstUniqueAncestorSecurableObject"
          }
        },
        "RoleAssignments": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/RoleAssignments"
          }
        },
        "AttachmentFiles": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/AttachmentFiles"
          }
        },
        "ContentType": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/ContentType"
          }
        },
        "FieldValuesAsHtml": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/FieldValuesAsHtml"
          }
        },
        "FieldValuesAsText": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/FieldValuesAsText"
          }
        },
        "FieldValuesForEdit": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/FieldValuesForEdit"
          }
        },
        "File": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/File"
          }
        },
        "Folder": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/Folder"
          }
        },
        "ParentList": {
          "__deferred": {
            "uri": "https:\/\/contoso.sharepoint.com\/_api\/Web\/Lists(guid'c2477113-c582-4c57-bcc6-d4a5ea2e29c9')\/Items(8)\/ParentList"
          }
        },
        "FileSystemObjectType": 0,
        "Id": 8,
        "ContentTypeId": "0x0100BC97B2F575CB0C42B79549F3BABD32A8",
        "Title": "Nokia MEA",
        "Address": "Al Thuraya Tower II, 27th floor, Dubai Internet City\nDubai, UAE",
        "ID": 8,
        "Modified": "2014-02-24T10:10:53Z",
        "Created": "2014-02-24T10:10:53Z",
        "AuthorId": 12,
        "EditorId": 12,
        "OData__UIVersionString": "1.0",
        "Attachments": false,
        "GUID": "ba897f84-ccbb-4938-a6ce-b9705d3d3a63"
      }
    ]
  }
}

and saved as a string into variable named $data

An attempt to convert a JSON-formatted string to a custom object using ConvertFrom-Json cmdlet:

$results = $data | ConvertFrom-Json

gives the following error:

ConvertFrom-Json : Cannot convert the JSON string because a dictionary that was converted from the string contains the duplicated keys 'Id' and 'ID'.

Is there any way to convert the specified JSON-formatted string in PowerShell?

回答1:

In PowerShell V1.0, or in PowerShell V2.0 when the JSON is too big, I still use a convertion to XML :

Add-Type -AssemblyName System.ServiceModel.Web, System.Runtime.Serialization
function Convert-JsonToXml
{
  PARAM([Parameter(ValueFromPipeline=$true)][string[]]$json)

  BEGIN
  { 
    $mStream = New-Object System.IO.MemoryStream 
  }

  PROCESS
  {
    $json | Write-String -stream $mStream
  }

  END
  {
    $mStream.Position = 0
    try
    {
       $jsonReader = [System.Runtime.Serialization.Json.JsonReaderWriterFactory]::CreateJsonReader($mStream,[System.Xml.XmlDictionaryReaderQuotas]::Max)
       $xml = New-Object Xml.XmlDocument
       $xml.Load($jsonReader)
       $xml
    }
    finally
    {
       $jsonReader.Close()
       $mStream.Dispose()
    }
  }
}

Using this code you can loop thru your items you can test :

$a = Get-Content C:\temp\jsontest.txt
$b.root.d.results.Item
$b.root.d.results.Item[7].Id[0].InnerText

(Edited)

In you case I would only replace the expected duplicate ID/Id

$data = Get-Content C:\temp\jsontest.txt -Raw
$datacorrected = $a -creplace '"Id":','"Id-minus":'
$psJsonIn = $datacorrected | ConvertFrom-Json

If really you've got unexpected duplicate you can write a function that trap the convertion error due to duplicated key and replace one.



回答2:

This is how I have done with it:

$results = $data.ToString().Replace("ID", "_ID") | ConvertFrom-Json


回答3:

ConvertFrom-JSON it going to try to create a PS Custom Object from the JSON string. PowerShell object property names are case-insensitive, so "ID" and "id" represent the same property name. You're going to have to do something with those duplicate property names in your JSON before you try to do that conversion, or it's going to fail.