Found this link on json.org
http://www.newtonsoft.com/products/json/ (example included)
I'm not an ASP.Net programmer but that looks like what you need. If
not, look into Jayrock (also a link from json.org)
Colin
Gareth Evans wrote:
Thanks Colin, thats what I thought.
I'm using ASP.Net, are you able to provide an example of an
array of hashes in JSON? I don't hve a json_encode function so not sure
what the output should be.
If it's not too much trouble.
I've looked at the json info on prototypejs.org but not much there,
and the json homepage didn't have a lot of examples from memory.
It's not urgent, more for my own knowledge for next time.
Gareth
On 4/3/07, Colin
Mollenhour <[EMAIL PROTECTED]>
wrote:
Prototype Core team decided not to support encoding/decoding of nested
arrays/hashes in parameter strings for various reasons, so JSON is
going
to be the way to go with this (and is better anyway). I don't know what
server-side platform you use, but in PHP a simple json_encode(<your
data
structure here>) will convert any array/hash (including nesting)
into a
JSON string. I recommend sending it through the body of the response,
not the X-JSON header because of header size limitations. So, on the
client-side, you can do this to get basically the exact same data
structure that you had on the server side into _javascript_:
var obj = transport.responseText.evalJSON();
So if what you passed to json_encode (or your equivalent) on the server
side was an array of hashes, "obj" would now be the same array of hashes
you had before and you can use Prototype Enumerables on it as you
please.
Colin
Gareth Evans wrote:
> Hey Guys
>
> Re: Nested hashes/arrays of hashes
>
> I know Colin was talking about this some time back but I just
wanted
> to clarify whether these actually work...
> I had a scenario where I wanted to return effectively an array of
> hashes (though nested hashes would be better) for metadata about
form
> fields (to implement a cascading requirement)
>
> eg:
> Client sends "Field 1 changed to 2"
> Server replies with
> {fieldid:'fielda',properties:{required:true,label:'Field
> A'}},{fieldid:'fieldb',properties:{required:true,label:'Field B'}}
> (which in this case might be dependent on the fact that field1 has
> changed to 2, rather than 3 or 4)
> Client receives reply and loads the data and iterates through the
> received meta setting the various properties as appropriate.
>
> However, I wasn't sure what the format of the reply should be in
order
> to implement such functionality.
> It doesn't need the nested hashes but I do need to return an array
of
> hashes.
> I think I returned a 1 dimensional ~ seperated array and then
split it
> to iterate but I'm sure there's a better way.
>
> Could someone give me an example of the reply and the method to
get it
> into a hash, if not just $H(transport.responseText)
> I tried the $H method as well as the toJSON (or is it fromJSON, i
cant
> remember)
>
> Gareth
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
|
- [Rails-spinoffs] Re: Hashes, Arrays/Nested Colin Mollenhour
-