From: "ara.t.howard" Date: 2008-09-07T13:18:13+09:00 Subject: Re: json for extjs (without rails) On Sep 6, 2008, at 9:06 PM, Gurpal 2000 wrote: > Ara Howard wrote: >> On Sep 6, 2008, at 6:52 PM, Gurpal 2000 wrote: >> >>> class car >>> into >>> an EXTJS grid. >>> >>> Thanks >> >> >> gem install json >> ri json >> >> a @ http://codeforpeople.com/ > > an example would actually be helpful. i already looked at the rdoc, > i'm > a ruby beginner. No example anywhere on google either... There seem to > be examples to parse and unparse but those are simple one liners > with no > solid object conversions. > > thanks > -- > Posted via http://www.ruby-forum.com/. > cfp:~ > cat a.rb # i prefer the pure-ruby version of json # require 'rubygems' require 'json' # gem install json_pure OR gem install json # it's easiest to just use mixtures of hash, arrays, strings, and numbers # because this translates 1-1 with javascript # hash = { 'key' => 42 } hash2 = { 'another key' => 42.0 } data = [ hash, hash2 ] puts data.to_json puts # even if you defined your own classes i personally prefer to translate to # 'simple' javascript structures # class C def initialize a, b @a, @b = a, b end def to_json { 'a' => @a, 'b' => @b }.to_json end end puts C.new(4, 2).to_json cfp:~ > ruby a.rb [{"key":42},{"another key":42.0}] {"a":4,"b":2} a @ http://codeforpeople.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama