JsonResult相当于[DataMember(Name =“ Test”)]
我有一个方法这样做:
public JsonResult Layar(string countryCode, string timestamp, string userId,
string developerId, string layarName, double radius,
double lat, double lon, double accuracy)
{
LayarModel model = new LayarModel(lat, lon, radius);
return Json(model, JsonRequestBehavior.AllowGet);
}
它返回此对象:
public class LayarModel
{
private List<HotSpot> _hotSpots = new List<HotSpot>();
public List<HotSpot> HotSpots { get { return _hotSpots; } set { _hotSpots = value; } }
public string Name { get; set; }
public int ErrorCode { get; set; }
public string ErrorString { get; set; }
}
我想要JSON
{"hotspots": [{
"distance": 100,
"attribution": "The Location of the Layar Office",
"title": "The Layar Office",
"lon": 4884339,
"imageURL": http://custom.layar.nl/layarimage.jpeg,
"line4": "1019DW Amsterdam",
"line3": "distance:%distance%",
"line2": "Rietlandpark 301",
"actions": [],
"lat": 52374544,
"type": 0,
"id": "test_1"}],
"layer": "snowy4",
"errorString": "ok",
"morePages": false,
"errorCode": 0,
"nextPageKey": null
}
一切都像归来的类一样大写(HotSpots
而不是hotspots
)。
我尝试过DataContract和DataMembers(Name =“Test”),但这不起作用。有什么建议?
没有找到相关结果
已邀请:
2 个回复
樊熄忙暖
补蹲农界维
这是使用它的一个例子。
需要注意的部分是解决你的问题,特别是当
上的
设置为使用
时 这样您就不必再次设置自定义命名。