I know, I meant it won't handle actual arrays like [1,2,3]. Wasn't needed at the time, probably not too difficult to implement.
On Jun 22, 9:24 pm, Josh Powell <seas...@gmail.com> wrote: > That's okay, javascript doesn't have associative arrays, only arrays > with object properties. > > On Jun 22, 2:45 pm, Ricardo <ricardob...@gmail.com> wrote: > > > before someone complains: that function won't handle arrays (only > > objects) > > > On Jun 22, 6:39 pm, Ricardo <ricardob...@gmail.com> wrote: > > > > Usually you'll send out parameters in query strings, only receive data > > > in JSON, which is what jQuery is equipped to do. If you don't want the > > > weight of a plugin you could use something like this: > > > > function toJSON(obj){ > > > var json = '({'; > > > $.each(obj, function(k,v){ > > > var q = typeof v == 'string' ? ~v.indexOf("'") ? '"' : "'" : ''; > > > if (typeof v == 'object') > > > v = toJSON(v).slice(0,-1).substr(1); > > > json+= k + ':'+ q + v + q + ',';}); > > > > return json.slice(0,-1)+'})'; > > > > }; > > > > On Jun 21, 11:23 pm, Nic Hubbard <nnhubb...@gmail.com> wrote: > > > > > I have been trying to figure out how I could go from an associative > > > > array to JSON. Is there a function for this?