I am trying to parse a response from the simplegeo API, I believe it is JSON format? I am able to display the raw content on a page by referencing a variable in that page's controller. Is there a simple way to 开发者_开发技巧clean up the response so it is not a jumbled mess?
I currently have this in the "view" of the particular page to display the response:
<%= @simple_geo_client %>
I'm guessing you get the answer back as a JSON-string. You can parse this using
api_object = ActiveSupport::JSON.decode(api_response)
This returns the data as a hash object. You can now access the attributes by simply doing api_object["my_attribute"].
Are you not using the official Ruby plugin though? You can find it here.
精彩评论