1

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

Manoj Singh
  • 7,569
  • 34
  • 119
  • 198

2 Answers2

1

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

Community
  • 1
  • 1
Tolo Palmer
  • 1,760
  • 2
  • 17
  • 27
  • Ok then how can I show all above text in new line as this string is made from using StringBuilder.AppendLine, pleas suggest – Manoj Singh Feb 03 '12 at 11:34
  • I gues you may split the longest string and then use foreach in order to print it – Tolo Palmer Feb 03 '12 at 11:37
  • Sorry, check this example: {"result": [ "CreateCityKeys", "0xxxxxx" , "1xxxx", ... "Nxxxx" ]} And then just do something like foerach (item : jsonX.result) { print item } – Tolo Palmer Feb 03 '12 at 11:51
0

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>');
});
Tolo Palmer
  • 1,760
  • 2
  • 17
  • 27
  • Hwy Toloo, I don't want to print all the string only the result[1] as I don't want to print "CreateCityKeys", and also it will not be easier to make above format string as it is created dynamically, please suggest another way – Manoj Singh Feb 04 '12 at 06:12
  • tell us what you really want..., is is just 2nd item (means result[1]) just replace $each.... with document.write(x.result[1]); is that ok? – Tolo Palmer Feb 06 '12 at 09:33