【发布时间】:2014-02-27 21:05:02
【问题描述】:
从 OData API 服务返回以下 JSON:
{
"d": {
"results": [
{
"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"
}
]
}
}
并作为字符串保存到名为$data的变量中
尝试使用ConvertFrom-Json cmdlet 将 JSON 格式的字符串转换为自定义对象:
$results = $data | ConvertFrom-Json
给出以下错误:
ConvertFrom-Json : 无法转换 JSON 字符串,因为字典 从字符串转换的包含重复键“Id” 和“身份证”。
有没有办法在PowerShell中转换指定的JSON格式的字符串?
【问题讨论】:
标签: json rest powershell