C# 分析值时遇到意外字符:[

C# 分析值时遇到意外字符:[,c#,json,azure,azure-active-directory,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@gm

我的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对象j=JsonConvert.DeserializeObject(成员);
MyObject类如下所示

{
   "@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"
      }
   ]
}
公共类MyError
{
公共列表值;
}
公共阶级价值观
{
公共字符串id;
公共字符串userPrincipalName;
公共字符串姓氏;
公共字符串首选语言;
公共字符串定位;
公共电话;
公共字符串邮件;
公开职位;
公共字符串givenName;
公共字符串显示名;
公用电话;
}
转换时,我遇到以下错误

分析值[0]时遇到意外字符:[.Path'值[0]。businessPhones',第1行,位置97


当我从类中删除公共字符串businessPhones;时,其余数据将解析到对象列表。但实际上我还需要businessPhones,正如一些人指出的那样,您应该将businessPhones声明为数组:

public string[] businessPhones;

什么是
public List value;
中的
List
?另外
businessPhones
是JSON中的一个数组。JSON反序列化问题的简单解决方案如下:将您的模型与JSON进行比较。
businessPhones
多值
字段,您必须定义为字符串。
businessPhones
似乎是一个字符串的数组,因此您应该将其声明为suchthank,因为将BusinessPhone转换为数组列表解决了此问题