2015-07-20 49 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'} 
     }) 
};