I try to implement an api for a projekt and found this article http://www.coffeepowered.net/2009/02/16/powerful-easy-dry-multi-format-rest-apis-part-2/
So i get a xml.builder template to build my response and render it to json. It works great, but I have some utf-8 encoded Data I want to respond. First I specify the xml encoding. Next i tryed to surround my utf-8 Data with a CDATA tag.
This works great for the xml request. But the Json has still some bad escaping like "\u00fc" for "ü".
when i generate a Has from the xml i got the right encoding using nokogiri like here "http://gist.github.com/335286".
But when i render :json it escape the characters
a console output:
ruby-1.8.7-p174 > xml = "<?xml version='1.0' encoding='UTF-8'?><node><![CDATA[some utf-8 äöüü]]></node>"
=> "<?xml version='1.0' encoding='UTF-8'?><node><![CDATA[some utf-8 äöüü]]></node>"
ruby-1.8.7-p174 > hash = Hash.from_xml(xml)
=> {"node"=>"some utf-8 äöüü"}
ruby-1.8.7-p174 > hash.to_json
=> "{\"node\":\"some utf-8 \\u00e4\\u00f6\\u00fc\\u00fc\"}"