我有一个json回复
{
"name" : "xxx",
"address":"xxx"
}
我如何改变这个如下例
cd(
{
"name" : "xxx",
"address":"xxx"
}
)
我正在使用c#来获取响应并将其发回
答案 0 :(得分:0)
您可以通过以下方式从web api返回json结果:
return Request.CreateResponse(HttpStatusCode.OK, new {cd=YourDataList});
并将 “Newtonsoft.Json”软件包 从nuget.org添加到您的项目中,然后将此代码添加到webApiConfig.cs
public static void Register(HttpConfiguration config)
{
config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented;
}