为什么Breeze Web API实现使用字符串而不是JSON对象来响应元数据请求? [英] Why does the Breeze Web API implementation respond to metadata requests with a string instead of a JSON object?

查看:83
本文介绍了为什么Breeze Web API实现使用字符串而不是JSON对象来响应元数据请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有Breeze Web API实现对任何元数据请求的响应返回字符串而不是JSON对象?



发送元数据,因为文本会增加网络(由于编码)及其他方面的开销。客户端应有手动JSON.parse。



我认为您的控制器只需指定contentType标头即可将元数据作为JSON返回:

  [HttpGet] 
public HttpResponseMessage Metadata()
{
var result = new HttpResponseMessage {Content = new StringContent(_contextProvider.Metadata())};
result.Content。 Headers.ContentType = new MediaTypeHeaderValue( application / json);
返回结果;
}


他的 BreezeController 属性现在可以自动执行此操作...。并感谢您的建议。


Is there any reason that the Breeze Web API implementation of the response to any metadata requests returns a string instead of a JSON object?

Sending metadata as text adds a lot of overhead over the network (due " encoding) and on clientside due manual JSON.parse.

I think that your controller can simply return the Metadata as JSON by specifying the contentType header: i.e.

[HttpGet]
public HttpResponseMessage Metadata()
{
    var result = new HttpResponseMessage { Content = new StringContent(_contextProvider.Metadata())};
    result.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
    return result;
 }

解决方案

As of v 1.2.7, the BreezeController attribute now does this automatically.... and thanks for the idea.

这篇关于为什么Breeze Web API实现使用字符串而不是JSON对象来响应元数据请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆