2015-07-20 81 views
0

以下JSON對象映射正確。它將所有字段映射到我的Web API模型(partNumbersReturned數組除外)。 Web API上的模型是否看起來不一樣?這裏是JSON對象:具有數組的複雜JSON對象不映射到Web API模型?

$scope.carbForm = 
      { 
       ownerInformation: 
       { 
        fullName: "", 
        email: "", 
        street1: "", 
        street2: "", 
        city: "", 
        state: "", 
        zip: "" 
       }, 
       newOwnerInformation: 
       { 
        fullName: "", 
        email: "", 
        street1: "", 
        street2: "", 
        city: "", 
        state: "", 
        zip: "" 
       }, 
       vehicleInformation: { 
        vin: "", 
        vehicleMake: "", 
        vehicleModel: "", 
        vehicleYear: "" 
       }, 
       productInformation: { 
        productStatus: "", 
        otherExplanation: "", 
        partNumbersReturned: [] 
       } 
      }; 

這裏是我的Web API型號:

public class CarbForm 
{ 

    public int Id { get; set; } 

    public VehicleInformation VehicleInformation { get; set; } 
    public OwnerInformation OwnerInformation { get; set; } 
    public NewOwnerInformation NewOwnerInformation { get; set; } 
    public ProductInformation ProductInformation { get; set; } 
} 

的ProductInformation的定義是這樣的:

public class ProductInformation 
{ 
    public string ProductStatus { get; set; } 
    public string OtherExplanation { get; set; } 
    public List<string> PartNumbersReturned { get; set; } 
} 

回答

0

看樣子你可能會在使用角客戶端?通過使用JSON.stringify(),確保您在發佈到API之前正確序列化對象。例如:

$http({ 
     url: '/helloWorld/', 
     method: "POST", 
     data: JSON.stringify(yourObject), 
     headers: {'Content-Type': 'application/json'} 
     }) 
};