On Jul 30, 3:54 am, Vuong Hung
<li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>
wrote:> Hi everybody.
>
> I have using ActiveSupport::JSON library in rails
>
> I have a json string:
> test=
{"C1":{"id":"C1","mode":"new","type":"block","name":"new
block
>
C1","unit":"","choices":[],"index":10},"R1":{"id":"R1","mode":"new","type":
"text","name":"new
> question
>
R1","unit":"","choices":[""],"index":20},"R2":{"id":"R2","mode":"new","type
":"text","name":"new
> question
>
R2","unit":"","choices":[""],"index":30},"R3":{"id":"R3","mode":"new","type
":"text","name":"new
> question
>
R3","unit":"","choices":[""],"index":40},"C2":{"id":"C2","mode":"new","type
":"block","name":"new
> block
>
C2","unit":"","choices":[],"index":50},"R4":{"id":"R4","mode":"new","type":
"text","name":"new
> question
>
R4","unit":"","choices":[""],"index":60},"C3":{"id":"C3","mode":"new","type
":"block","name":"new
> block
C3","unit":"","choices":[],"index":70}}
>
That is not a string, but trying to assign a new hash to test. I''ll
assume that the you just posted test= to define your problem.
> when i using:
>
> temp = ActiveSupport::JSON
> result = temp.decode(test)
>
The call to decode will create a hash From ruby-doc.org:
"A Hash is a collection of key-value pairs. It is similar to an Array,
except that indexing is done via arbitrary keys of any object type,
not an integer index. The order in which you traverse a hash by either
key or value may seem arbitrary, and will generally not be in the
insertion order."
result = result.sort
<%= result.inspect %>
Seems to sort your hash by the keys. If input order is what you are
looking for, not sure how to help without modifying your keys
(prepending an index).
Steve Alex
--
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.