[jQuery] Re: How to serialize an Object to JSON String without making it POST like?

2008-09-17 Thread Namlet

So I need to write my own JSON serializer or is there something
already available?

If I do need to write my own, how can I contribute it back to the
community?

Thanks!

On Sep 16, 4:28 pm, Mike Alsup [EMAIL PROTECTED] wrote:
  When I use this function to create a JSON object:

  var formObject = $(:input).serialize();

  and I print it, I get name=valuename=value...  This isn't proper
  JSON string and the .NET webservice I'm sending it to barfs.

  How can I make it stay in the proper format, i.e.

  {'fname':'dave', 'lname':'ward'}

  Thanks!

 jQuery's serialize method does not create JSON strings.  It creates
 URL-encoded strings, as you discovered.


[jQuery] Re: How to serialize an Object to JSON String without making it POST like?

2008-09-17 Thread Mike Alsup

 So I need to write my own JSON serializer or is there something
 already available?

 If I do need to write my own, how can I contribute it back to the
 community?

I consider this the defacto standard:

http://www.json.org/json2.js

And IE8's native JSON API is exactly the same as the one in json2.js.

Mike


[jQuery] Re: How to serialize an Object to JSON String without making it POST like?

2008-09-17 Thread MorningZ

So I need to write my own JSON serializer or is there something
already available?

it's not all that involved

var FormValues = {};
$(:input).each(function() {
  FormValues[$(this).attr(name)] = $(this).val();
});

Something along those lines anyways


[jQuery] Re: How to serialize an Object to JSON String without making it POST like?

2008-09-16 Thread Mike Alsup

 When I use this function to create a JSON object:

 var formObject = $(:input).serialize();

 and I print it, I get name=valuename=value...  This isn't proper
 JSON string and the .NET webservice I'm sending it to barfs.

 How can I make it stay in the proper format, i.e.

 {'fname':'dave', 'lname':'ward'}

 Thanks!


jQuery's serialize method does not create JSON strings.  It creates
URL-encoded strings, as you discovered.