来自服务器的 OData JSON 响应返回行返回字符

发布于 2024-10-11 16:14:32 字数 2170 浏览 8 评论 0原文

当您向 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

三五鸿雁 2024-10-18 16:14:32

这是上一个版本中的一个已知问题。在下一个版本中,我们将修复代码以永远不缩进响应负载。如果客户

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文