From: Smp Mp on 7 Apr 2010 11:10 Hi, I have an xml which i need in ruby json format I use the below code : data=Hash.from_xml(xml).to_json() where xml contains the xml data. i get the result in the below format : {'responseHeader':{'status':0,'QTime':0}} but i require the result as : { 'responseHeader'=>{ 'status'=>0, 'QTime'=>0} } Kindly help -- Posted via http://www.ruby-forum.com/.
From: Brian Candler on 7 Apr 2010 11:38 Smp Mp wrote: > I use the below code : > > data=Hash.from_xml(xml).to_json() > > where xml contains the xml data. > i get the result in the below format : > > {'responseHeader':{'status':0,'QTime':0}} That looks like valid JSON to me. > but i require the result as : > { > 'responseHeader'=>{ > 'status'=>0, > 'QTime'=>0} > } That's not valid JSON. You mean you want a Ruby Hash? Try data = Hash.from_xml(xml) (there's no point converting it into JSON if you're going to JSON.parse it back into a hash) -- Posted via http://www.ruby-forum.com/.
From: Smp Mp on 7 Apr 2010 18:35 Thanks. -- Posted via http://www.ruby-forum.com/.
|
Pages: 1 Prev: Getting output of program with some DRb for good measure Next: Dissapearing data from array |