From: Gurpal 2000 Date: 2008-09-16T08:39:32+09:00 Subject: Re: json for extjs (without rails) Gurpal 2000 wrote: >> cfp:~ > ruby a.rb >> [{"key":42},{"another key":42.0}] >> >> {"a":4,"b":2} >> >> >> a @ http://codeforpeople.com/ > > I have another question. If I do something like this: > > mydata = [ C.new(4, 2).to_json, C.new(1, 3).to_json, C.new(5, 6).to_json > ] > myhash = { 'data' => mydata } > puts myhash.to_json > > 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: {"data":["{\"a\":\"acar\",\"b\":2}","{\"a\":\"ccar\",\"b\":6}","{\"a\":\"bcar\",\"b\":3}"]} what i need is something like { data: [ { data1 }, { data2 }, ... ] } thanks -- Posted via http://www.ruby-forum.com/.