【发布时间】:2012-10-29 04:23:19
【问题描述】:
我正在使用 iOS 应用程序中的 RestKit 连接到我们在 C# .Net 4 中构建的 Web API 服务。
我在这里遇到了同样的问题:RestKit non-kvc object mapping
基本上 C# 返回类似:
格式化的原始数据 身体
[
{
"Id":6,
"Guid":"00000000-0000-0000-0000-000000000000",
"Owner":null,
"Message":"Testing Wom#10",
"HashTags":null,
"createdtime":"2012-10-28T00:00:00",
"PlayedCount":100,
"DurationInSecs":150.0,
"FileSizeInBytes":20000,
"FileUrl":"http://www.wom.com"
}
]
而 RestKit 期望的标准格式是
{"woms": [
{
"Id":6,
"Guid":"00000000-0000-0000-0000-000000000000",
"Owner":null,
"Message":"Testing Wom#10",
"HashTags":null,
"createdtime":"2012-10-28T00:00:00",
"PlayedCount":100,
"DurationInSecs":150.0,
"FileSizeInBytes":20000,
"FileUrl":"http://www.wom.com"
}
]
我不在乎使用某种方式,但是,从 iOS 方面来看,让 C# 返回“客户”类名似乎更容易。
我如何告诉 C# 返回它?
谢谢。
这是我在 C# 中的 ApiController 中的当前代码:
namespace WomWeb.Controllers.Apis
{
[Authorize]
public class WomsController : ApiController
{
private WomContext db = new WomContext();
// GET api/Woms
public IEnumerable<Wom> GetWoms()
{
return db.Woms.AsEnumerable();
}
【问题讨论】:
标签: c# json restkit asp.net-web-api