我控制器JSON格式类似这样的压扁了MVC结合
return Json(customer);
返回一个对象图表视图在我的JSON对象看起来像这样
{
Name: 'Joe',
Budget: { Amount: 500, Spend: 100 }
}
认为一个复杂的JSON对象,正确映射到我的客户对象:
public class Customer
{
public string Name {get;set;}
public Budget Budget{get;set;}
}
public class Budget
{
public decimal Amount{get;set;}
public decimal Spend{get;set;}
}
我想通过相同的JSON对象回anoth
public ActionResult Method(Customer customer)
当我做这个客户的名字将会被填充,但不是预算类,我明白为什么,因为ModelBinder的期待是::{名称:“乔”,“预算与此签名的控制器上ER方法.Amount':500,'Budget.Spend':100}
所以我必须选择: 1.我可以按照它想要的格式返回json对象,但是我不知道如何,因为你可以'吨做到这一点:
return Json(new { Budget.Amount= 500})
- 我可以在客户端压扁json对象。有插件或方法来做到这一点?
但你可以做到这一点,对吧?不知道这是否解决了您的整个问题: return Json(new {Budget = new {Amount = 500}}) – RationalGeek 2010-02-05 21:43:09
我在尝试扁平化json对象,以便结果为'{'Budget.Amount'= 500}' – adriaanp 2010-02-05 21:47:29