当字符串返回到 JSONP Jquery 调用时出现无效 JSON 错误

发布于 2025-01-02 12:16:42 字数 1130 浏览 1 评论 0原文

我有下面的 JSONP 完整字符串,它从我的 aspx 页面返回到客户端。

"processjsonp({\"result\": [\"CreateCityKeys\", \"Keyword -Spokane already exists in City\r\nKeyword -Anchorage already exists in City\r\nKeyword -Fairbanks already exists in City\r\nKeyword -Bellingham already exists in City\r\nKeyword -Juneau already exists in City\r\nKeyword -Boise already exists in City\r\nKeyword -Victoria already exists in City\r\nKeyword -Kelowna already exists in City\r\nKeyword -Eugene already exists in City\r\nKeyword -Medford already exists in City\r\nKeyword -Tucson already exists in City\r\nKeyword -Walla Walla already exists in City\r\nKeyword -Wenatchee already exists in City\r\nKeyword -Pasco already exists in City\r\nKeyword -Pullman already exists in City\r\nKeyword -Redmond already exists in City\r\nKeyword -Yakima already exists in City\r\nKeyword -Ketchikan already exists in City\r\nKeyword -Kauai Island already exists in City\r\nKeyword -Kona already exists in City\r\nKeyword -Kahului already exists in City\r\n\"]})"

我知道错误一定是由于之间的 \r\n 造成的,请建议消除它。

谢谢

女士。

编辑:错误 - JSONP 解析器错误

I am having below JSONP full string which is return back to clientside from my aspx page.

"processjsonp({\"result\": [\"CreateCityKeys\", \"Keyword -Spokane already exists in City\r\nKeyword -Anchorage already exists in City\r\nKeyword -Fairbanks already exists in City\r\nKeyword -Bellingham already exists in City\r\nKeyword -Juneau already exists in City\r\nKeyword -Boise already exists in City\r\nKeyword -Victoria already exists in City\r\nKeyword -Kelowna already exists in City\r\nKeyword -Eugene already exists in City\r\nKeyword -Medford already exists in City\r\nKeyword -Tucson already exists in City\r\nKeyword -Walla Walla already exists in City\r\nKeyword -Wenatchee already exists in City\r\nKeyword -Pasco already exists in City\r\nKeyword -Pullman already exists in City\r\nKeyword -Redmond already exists in City\r\nKeyword -Yakima already exists in City\r\nKeyword -Ketchikan already exists in City\r\nKeyword -Kauai Island already exists in City\r\nKeyword -Kona already exists in City\r\nKeyword -Kahului already exists in City\r\n\"]})"

I know the error must be beacuse of \r\n in between, please suggest to get rid of this.

Thanks

M.S.

EDIT: Error - JSONP parser error

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

请止步禁区 2025-01-09 12:16:42

您的 JSON 语法不正确,您可以将 \" 替换为 " 并检查解析器字符串限制 这里讨论关于这个

Your JSON syntax is not correct, You may replace \" with just " and chech the parser string limitation here talks about this

荒岛晴空 2025-01-09 12:16:42

服务器响应示例:

json = {"result": ["CreateCityKeys", "Keyword -Spokane already exists in City", "Keyword -Anchorage already exists in City", "Keyword -Fairbanks already exists in City", "Keyword -Bellingham already exists in City", "Keyword -Juneau already exists in City", "Keyword -Boise already exists in City", "Keyword -Victoria already exists in City", "Keyword -Kelowna already exists in City", "Keyword -Eugene already exists in City", "Keyword -Medford already exists in City", "Keyword -Tucson already exists in City", "Keyword -Walla Walla already exists in City", "Keyword -Wenatchee already exists in City", "Keyword -Pasco already exists in City", "Keyword -Pullman already exists in City", "Keyword -Redmond already exists in City", "Keyword -Yakima already exists in City", "Keyword -Ketchikan already exists in City", "Keyword -Kauai Island already exists in City", "Keyword -Kona already exists in City", "Keyword -Kahului already exists in City",]}

jquery 演示:

x = jQuery.parseJSON( json )
$.each(x.result, function(i, item){
    document.write('<p>' + item + '</p>');
});

example server response:

json = {"result": ["CreateCityKeys", "Keyword -Spokane already exists in City", "Keyword -Anchorage already exists in City", "Keyword -Fairbanks already exists in City", "Keyword -Bellingham already exists in City", "Keyword -Juneau already exists in City", "Keyword -Boise already exists in City", "Keyword -Victoria already exists in City", "Keyword -Kelowna already exists in City", "Keyword -Eugene already exists in City", "Keyword -Medford already exists in City", "Keyword -Tucson already exists in City", "Keyword -Walla Walla already exists in City", "Keyword -Wenatchee already exists in City", "Keyword -Pasco already exists in City", "Keyword -Pullman already exists in City", "Keyword -Redmond already exists in City", "Keyword -Yakima already exists in City", "Keyword -Ketchikan already exists in City", "Keyword -Kauai Island already exists in City", "Keyword -Kona already exists in City", "Keyword -Kahului already exists in City",]}

demo with jquery:

x = jQuery.parseJSON( json )
$.each(x.result, function(i, item){
    document.write('<p>' + item + '</p>');
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文