[MacRuby-devel] UTF8 Strings
s.ross
cwdinfo at gmail.com
Sat Dec 5 13:45:21 PST 2009
My code receives XML data from a Web Service API call that is in UTF8 encoding. This winds up in a string.
return_data = NSURLConnection.sendSynchronousRequest(@request, returningResponse: response, error: error)
str = NSString.alloc.initWithData(return_data, encoding: NSUTF8StringEncoding)
puts "******* response encoding it #{str.encoding}"
The result of the puts above is 'MACINTOSH'.
I suspect the encoding of the string is not UTF-8, because when I try to parse the XML using REXML, I get:
RegexpError: too short multibyte code
This occurs way in REXML:
/Library/Frameworks/MacRuby.framework/Versions/0.5/usr/lib/ruby/1.9.0/rexml/text.rb:132:in `check:'
In any case, my questions are:
1) If anyone has run across this what did you do?
2) Why might the encoding be MACINTOSH and not UTF-8, as specified in the initWithData method call?
3) Suggestions?
Thanks,
Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-devel/attachments/20091205/58267897/attachment.html>
More information about the MacRuby-devel
mailing list