Manoj Singh
Manoj Singh

Reputation: 7707

Getting Invalid JSON error when string returned back to JSONP Jquery Call

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

Upvotes: 1

Views: 929

Answers (2)

Tolo Palmer
Tolo Palmer

Reputation: 1780

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

Upvotes: 0

Tolo Palmer
Tolo Palmer

Reputation: 1780

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

Upvotes: 1

Related Questions