Given a string in the following format (the Posterous API returns posts in this format):
s="\\u003Cp\\u003E"
How can I convert it to the actual ascii characters such that s="<p>"
?
On OSX, I successfully used Iconv.iconv('ascii', 'java', s)
but once deployed to Heroku, I receive an Iconv::IllegalSequence
exception. I'm guessing that the system Heroku deploys to does't support the java
encoder.
I am using HTTParty to make a request to the Posterous API. If I use curl to make the same request then I do not get the double slashes.
From HTTParty github page:
Automatic parsing of JSON and XML into ruby hashes based on response content-type
The Posterous API returns JSON (no double slashes) and HTTParty's JSON parsing is inserting the double slash.
Here is a simple example of the way I am using HTTParty to make the request.
class Posterous
include HTTParty
base_uri "http://www.posterous.com/api/2"
basic_auth "username", "password"
format :json
def get_posts
response = Posterous.get("/users/me/sites/9876/posts&api_token=1234")
# snip, see below...
end
end
With the obvious information (username, password, site_id, api_token) replaced with valid values.
At the point of snip, response.body
contains a Ruby string that is in JSON format and response.parsed_response
contains a Ruby hash object which HTTParty created by parsing the JSON response from the Posterous API.
In both cases the unicode sequences such as \u003C
have been changed to \\u003C
.
format
command that lets you specify the format being returned and to be parsed. Do you have that set? – Toothlessformat :json
doesn't affect the result at all. – Ballflower