解析值时遇到意外字符:[

时间:2019-07-29 04:38:58

标签: c# json azure azure-active-directory

我的JSON如下

{
   "@odata.context":"https://graph.microsoft.com/V1.0/$metadata#users",
   "value":[
      {
         "businessPhones":[

         ],
         "displayName":"dee",
         "givenName":null,
         "jobTitle":null,
         "mail":"79@gmail.com",
         "mobilePhone":null,
         "officeLocation":null,
         "preferredLanguage":null,
         "surname":null,
         "userPrincipalName":"79_gmail.com#EXT#@web.onmicrosoft.com",
         "id":"08fab3-6f-4dc9-9ffb-6568d172"
      },
      {
         "businessPhones":[
            "973"
         ],
         "displayName":"Technologies LLP",
         "givenName":"SHA",
         "jobTitle":null,
         "mail":null,
         "mobilePhone":"8762",
         "officeLocation":null,
         "preferredLanguage":"en-U",
         "surname":"SHAI",
         "userPrincipalName":"admin@web.onmicrosoft.com",
         "id":"2adf-94cd-45-83ef-d0dbf1e36"
      },
      {
         "businessPhones":[

         ],
         "displayName":"admin of smartogle",
         "givenName":null,
         "jobTitle":null,
         "mail":null,
         "mobilePhone":null,
         "officeLocation":null,
         "preferredLanguage":"en-US",
         "surname":null,
         "userPrincipalName":"admin@smartogle.com",
         "id":"1754-d6-40-9ae2-d816063e"
      },
      {
         "businessPhones":[

         ],
         "displayName":"av",
         "givenName":null,
         "jobTitle":null,
         "mail":null,
         "mobilePhone":null,
         "officeLocation":null,
         "preferredLanguage":"en-US",
         "surname":null,
         "userPrincipalName":"av@smartogle.com",
         "id":"6837-08-449-a6ab-78b"
      }
   ]
}

我正在使用以下代码将json转换为对象列表

MyObject obj = JsonConvert.DeserializeObject<MyObject>(members);

MyObject类如下

public class MyError
{
    public List<values> value;
}
public class values
{
    public string id;
    public string userPrincipalName;
    public string surname;
    public string preferredLanguage;
    public string officeLocation;
    public string mobilePhone;
    public string mail;
    public string jobTitle;
    public string givenName;
    public string displayName;
    public string businessPhones;

}

在进行转换时,出现以下错误

  

解析值[。时遇到意外字符。路径'value [0] .businessPhones',第1行,位置97。

当我删除公用字符串businessPhones时;从类中将其余数据解析到对象列表。但实际上我也需要businessPhones

1 个答案:

答案 0 :(得分:1)

几个人指出您应该将businessPhones声明为数组:

public string[] businessPhones;