hi,
The way an hash is serialized in json is the correct way i think, what you
want is more an array than an hash...

So you could either use an array

var a = $A();
a.push({"name00": "value00"});
a.push({"name01": "value01"});
and then serialize this array :
Object.toJSON(a);

or if it is too much work, you could serialize your hash this way

var h = $H();
h.set("name00", "value00");
h.set("name01", "value01");
Object.toJSON( h.inject([], function(acc, hashEntry) {
  var tmp = {};
  tmp[hashEntry.key] = hashEntry.value;
  acc.push(tmp);
  return acc;
}));

if you need this functionality at several places, you can add a method to
Hash to serialize the way you want :
Hash.addMethods( {
  myExpectedFormat : function() {
    return this.inject([], function(acc, hashEntry) {
      var tmp = {};
      tmp[hashEntry.key] = hashEntry.value;
      acc.push(tmp);
      return acc;
   });
  }
} );
and then everywhere :
Object.toJSON( h.myExpectedFormat() );

On Thu, May 6, 2010 at 4:33 PM, chrysanthe m <chrysant...@gmail.com> wrote:

> Hi
> Can anyone help me understand this?  I can recreate a properly formatted
> JSONArray server-side, but I really want to know why Object.toJSON() didnt
> format it client-side correctly.
>
> On Thu, Apr 29, 2010 at 4:36 PM, chrysanthe m <chrysant...@gmail.com>wrote:
>
>> Hi
>> I have created a hash, added to it with set but when try
>> Object.toJSON(myHash) it produces one large JSONObject and not the proper
>> JSONArray format.  I would expect [{name00:value00},{name01:value01}...]
>> What I get is {name00:value00,name01:value00...}.  How do/can I get what I
>> expect?  tia.
>>
>
>  --
> 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-scriptacul...@googlegroups.com.
> To unsubscribe from this group, send email to
> prototype-scriptaculous+unsubscr...@googlegroups.com<prototype-scriptaculous%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/prototype-scriptaculous?hl=en.
>

-- 
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-scriptacul...@googlegroups.com.
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.

Reply via email to