Hi Nikhil,

Although you could try to fix this on the client side by removing the
enclosing quotes and changing the escaped double quotes within to just
double quotes, I think you're better off dealing with the server-side
so it's returning properly-formatting JSON data.  That'll pay off in
the long run, and I'm sure ASP.Net's web services stuff can be made to
return valid JSON.  If not, consider ditching using the web services
stuff and just use ASP.Net directly.

But if you're going to deal with it on the client-side, you can
probably do it with a regex (or a series of them) using JavaScript's
String.replace or Prototype's String.gsub.  Basically, look at the
string escaping rules in the spec[1] and apply them in reverse.  I
would suggest *not* being tempted by the easy option of just replacing
\" with "; you'll need to handle all of the single-character escapes
(' " \ b f n r t v, I think, but check) as well as hex escapes and
unicode escapes.

But again, almost certainly best to handle this by fixing what the
server's returning.  I searched for "+asp.net +"web service" +json"
and found quite a few articles, including this one[2] that says "The
default serialization of AJAX-based Web services is JSON." and "...one
of the major additions of the ASP.NET 2.0 AJAX Extensions is a JSON

[1] http://www.ecma-international.org/publications/standards/Ecma-262.htm
[2] http://msdn.microsoft.com/en-us/magazine/cc163499.aspx

T.J. Crowder
tj / crowder software / com

On Nov 2, 9:19 am, Nikhil <[EMAIL PROTECTED]> wrote:
> Hi,  Have just started using prototype with ASP.NET 2.0 AJAX
> Webservices and JSON two days ago, and have run into a very strange
> roadblock, ok let me explain the basic details of my app first :  My
> ASP.NET webservice has one function that returns a dataset in JSON
> format (I've manually transformed the dataset into JSON looping
> through the rows)...the webservice returns the value as a string
> (which was the only way I could get it to work)...now when I consume
> the webservice using AJAX.request, the transport.responseJSON remains
> a string not an object!  What seems to happen is that there's an extra
> set of double quotes wrapped around the string returned by the
> webservice...I have the feeling this is because of the webservice
> returning a string value.  Ok, now as a test, I modified the
> javascript evalJSON function to trim the quotes around the string
> before parsing it using eval...this still doesn't work if any of the
> parameters inside the JSON formatted string are enclosed in double
> quotes either, the reason being these get interpreted as \" which is
> invalid, essentially VB.NET: {""Count"":10} get translated to in
> transport.responseText as {\"Count\":10}...however as per JSON specs,
> parameter names and string values must be enclosed in double quotes,
> so can't do away with it!  If anyone could help out with this two-fold
> problem ie; double quotes around the returned webservice string
> result; and the \" issue, I would be eternally grateful!  If anyone
> has any code samples that would be super as well thanks!  Regards,
> Nikhil
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 

Reply via email to