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.
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.
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.
# 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
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
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.
# 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
I see that the output will double escape the values (they are actually
strings with all sorts of characters in my code).
I guess what i need is the to_json on the hash to call to_json in each
element of the array. What's the ruby-esque way to do this? I could do
it in long code but doesn't feel right. This should easy right?
On Sep 6, 2008, at 11:36 PM, Joel VanderWerf wrote:
--
we can deny everything, except that we have the possibility of being better. simply reflect on that.
h.h. the 14th dalai lama
I see that the output will double escape the values (they are actually
strings with all sorts of characters in my code).
I guess what i need is the to_json on the hash to call to_json in each
element of the array. What's the ruby-esque way to do this? I could do
it in long code but doesn't feel right. This should easy right?
Thanks
example if i put multiple Cars in a hash or asrray and then wrap that in
a "data" hash i get double quotes:
The funny thing is i've been trying that and it keeps on crapping out:
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:300:in
`to_json': wrong number of arguments (2 for 0) (ArgumentError)
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:300:in
`json_transform'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:299:in
`map'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:299:in
`json_transform'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:272:in
`to_json'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:251:in
`json_transform'
from U:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`map'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:245:in
`each'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:245:in
`map'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:245:in
`json_transform'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:218:in
`to_json'
from Z:/test.rb:116
The funny thing is i've been trying that and it keeps on crapping out:
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pureuby/gems/1.8//generator.rb:251:in
`json_transform'
from U:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
`map'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:245:in
`each'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:245:in
`map'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:245:in
`json_transform'
from
U:/ruby/lib/ruby/gems/1.8/gems/json_pure-1.1.3/lib/json/pure/generator.rb:218:in
`to_json'
from Z:/test.rb:116
BUMP! i'm still stuck here. Any ideas most appreciated.
This means that you are trying to supply two arguments to to_json,
when in fact you aren't supposed to have any. My guess is that the
example you're trying doesn't exactly match the above.
-- Mark.
···
On Sep 16, 2:44 am, Gurpal 2000 <gur...@gmx.com> wrote: