我使用這個代碼反序列化JSON字符串對象:嵌套的JSON字符串轉換爲自定義對象
var account = JsonConvert.DeserializeObject<LdapAccount>(result.ToString());
我收到此錯誤:
Error reading string. Unexpected token: StartArray. Path 'mail', line 8, position 12.
我知道這是因爲嵌套在JSON中,但不知道如何解決。我只關心我的自定義類中的屬性。
JSON字符串:
{
"DN": "cn=jdoe,ou=test,dc=foo,dc=com",
"objectClass": [
"inetOrgPerson",
"organizationalPerson",
"person"
],
"mail": [
"[email protected]"
],
"sn": [
"Doe"
],
"givenName": [
"John"
],
"uid": [
"jdoe"
],
"cn": [
"jdoe"
],
"userPassword": [
"xxx"
]
}
我的類:
public class Account
{
public string CID { get; set; }
public string jsonrpc { get; set; }
public string id { get; set; }
public string mail { get; set; }
public string uid { get; set; }
public string userPassword { get; set; }
}