来自服务器的 OData JSON 响应返回行返回字符
当您向 OData 服务器请求 JSON 时,JSON 响应会返回“\r\n”行。目前我正在剥离客户端线路返回的响应。有没有一种方法可以让 JSON 响应返回而不需要“漂亮的格式”而不需要“\r\n”行返回?
服务器响应:
{\r\n"d" : [\r\n{\r\n"__metadata": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(0)", "type": "ODataDemo.Category"\r\n}, "ID": 0, "Name": "Food", "Products": {\r\n"__deferred": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(0)/Products"\r\n}\r\n}\r\n}, {\r\n"__metadata": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(1)", "type": "ODataDemo.Category"\r\n}, "ID": 1, "Name": "Beverages", "Products": {\r\n"__deferred": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(1)/Products"\r\n}\r\n}\r\n}, {\r\n"__metadata": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(2)", "type": "ODataDemo.Category"\r\n}, "ID": 2, "Name": "Electronics", "Products": {\r\n"__deferred": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(2)/Products"\r\n}\r\n}\r\n}\r\n]\r\n}
预期响应:
{"d" : [{"__metadata": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(0)", "type": "ODataDemo.Category"}, "ID": 0, "Name": "Food", "Products": {"__deferred": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(0)/Products"}}}, {"__metadata": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(1)", "type": "ODataDemo.Category"}, "ID": 1, "Name": "Beverages", "Products": {"__deferred": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(1)/Products"}}}, {"__metadata": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(2)", "type": "ODataDemo.Category"}, "ID": 2, "Name": "Electronics", "Products": {"__deferred": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(2)/Products"}}}]}
When you ask the OData server for JSON, the JSON response comes back with "\r\n" line returns. Currently I'm stripping the response of the line returns on the client side. Is there a way to have the JSON response come back without the "pretty format" without the "\r\n" line returns?
Response from server:
{\r\n"d" : [\r\n{\r\n"__metadata": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(0)", "type": "ODataDemo.Category"\r\n}, "ID": 0, "Name": "Food", "Products": {\r\n"__deferred": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(0)/Products"\r\n}\r\n}\r\n}, {\r\n"__metadata": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(1)", "type": "ODataDemo.Category"\r\n}, "ID": 1, "Name": "Beverages", "Products": {\r\n"__deferred": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(1)/Products"\r\n}\r\n}\r\n}, {\r\n"__metadata": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(2)", "type": "ODataDemo.Category"\r\n}, "ID": 2, "Name": "Electronics", "Products": {\r\n"__deferred": {\r\n"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(2)/Products"\r\n}\r\n}\r\n}\r\n]\r\n}
Expected response:
{"d" : [{"__metadata": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(0)", "type": "ODataDemo.Category"}, "ID": 0, "Name": "Food", "Products": {"__deferred": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(0)/Products"}}}, {"__metadata": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(1)", "type": "ODataDemo.Category"}, "ID": 1, "Name": "Beverages", "Products": {"__deferred": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(1)/Products"}}}, {"__metadata": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(2)", "type": "ODataDemo.Category"}, "ID": 2, "Name": "Electronics", "Products": {"__deferred": {"uri": "http://services.odata.org/(S(cxfoyevtmm2e2elq52yherkc))/OData/OData.svc/Categories(2)/Products"}}}]}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是上一个版本中的一个已知问题。在下一个版本中,我们将修复代码以永远不缩进响应负载。如果客户
This is a known issue in the last release. In the next release, we will fix the code to never indent the response payload. If the client