无法将当前JSON数组反序列化为List<> '因为类型需要一个JSON对象“

时间:2015-05-29 14:12:53

标签: c# json serialization dotnet-httpclient

我正在接受

  

“无法将当前JSON数组(例如[1,2,3])反序列化为类型   'Mercury.TGC.Service.DTO.ContactResponseDto',因为类型需要   要正确反序列化的JSON对象(例如{“name”:“value”})。“

我做错了什么?

Json从API返回

{
"status": "Success",
"body": {
"companyName": "keep org merge test",
"taxId": "tax id2",
"addresses": [
{
"id": 100,
"addressName": "Location 1",
"address1": "1234 Create Ave",
"address2": "Suite 1234",
"city": "West Des Moines",
"state": "IA",
"postalCode": "50266",
"country": "USA",
"latitude": 41.575011,
"longitude": 93.709212,
"isPrimary": true,
"imageShortkey": "5a0lc9ge5n",
"types": [],
"phones": []
}
],
"phones": [
{
"id": 122,
"phoneNumber": "515-924-2452",
"phoneType": "Work",
"isPrimary": true,
"extension": null
},
{
"id": 123,
"phoneNumber": "515-326-1919",
"phoneType": "Work",
"isPrimary": false,
"extension": null
}
],
"id": 5100,
"searchOptOut": false,
"tradeCodes": [],
"doingBusinessAs": [],
"leedLevel": 3,
"hasBimExperience": true,
"facebookURL": null,
"twitterHandle": null,
"yearFounded": "1924",
"profileText": null,
"mainEmail": null,
"websiteURL": null,
"logoURL": null,
"currentEmr": 1.2
},
"messages": null
}

C#代码:

class RestfulResponseContactDto {
    public string Status {
        get;
        set;
    }
    public ContactResponseDto Body {
        get;
        set;
    }
    public List<string> Messages {
        get;
        set;
    }
}

public class ContactResponseDto {        
    public List<Contact> Contacts { get; set; } 
}

 public class Contact {
    public string Id { get; set; }
    public string OrgId { get; set; }
    public string FirstName { get;set; }
    public string LastName { get;set; }
    public string Email { get;set; }
     public string Title { get;set; }
    // public List<addresses> addresses { get; set; }
    //public List<phones> phones { get; set; } 
    //public List<string> Messages { get; set; }
    //public string RequestStatus { get;set; }
}

0 个答案:

没有答案