2012-02-03 44 views
1

我有下面的JSONP完整字符串,从我的aspx页面返回给客户端。当字符串返回到JSONP时获取无效的JSON错误Jquery调用

"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之间,请建议摆脱这一点。

谢谢

M.S.

编辑:错误 - JSONP解析错误

+0

请说明错误。 – 2012-02-03 11:22:48

+0

它只是一个解析器错误,当它回到客户端 – 2012-02-03 11:27:09

回答

1

你的JSON的语法不正确,你可以替换\“只有”和再检查一下解析器串限制here talks这个

+0

好吧然后我怎么能显示所有上面的文本在新行中,因为这个字符串是从使用StringBuilder.AppendLine,请认真建议 – 2012-02-03 11:34:27

+0

我觉得你可以拆分最长的字符串,然后使用foreach来打印它 – 2012-02-03 11:37:44

+0

你能清楚你想说什么吗? – 2012-02-03 11:48:19

0

例如服务器响应:

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>'); 
}); 
+0

Hwy Toloo建议,我不想打印所有字符串只有结果[1],因为我不想打印“CreateCityKeys”,并且在动态创建上面的格式字符串时不会更容易,请使用另一种方式 – 2012-02-04 06:12:49

+0

告诉我们你真正想要的是什么,仅仅是第二项(意味着结果[1])只需替换$。 ... with document.write(x.result [1]);这可以吗? – 2012-02-06 09:33:47

相关问题