title: Transferring HTML documents with JSON responses. Rails
body: <p>recently i`ve faced a problem parsing JSON responses, that contains html injections.</p>
  
  <pre><code> [{"Date":"\/Date(1316445326553+0400)\/",
   "Dishes":null,"Id":103,"Name":"Menutka уже с Вами!",
   "PictureId":130144,
   "TextHtml":"&lt;!DOCTYPE html PUBLIC '-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN' 'http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd'&gt;\u000a&lt;html xmlns='http:\/\/www.w3.org\/1999\/xhtml'&gt;\u000a&lt;head&gt;\u000a... etc",
   "Type":1,"UserId":1,"UserName":"Администратор"}]
  </code></pre>
  
  <p>and tried to do <code>JSON.parse response.body</code> where response body is my JSON. It silenly obeys, but returns empty collection. I tried to validate this json on <a href="http://jsonlint.com/" rel="nofollow">this site</a> and it says "It s valid"</p>
  
  <p>So i`m a bit confused about whats gone wrong. </p>
  
  <p>PS this is my parse method:</p>
  
  <pre><code>   def self.get(uri)
  raw_url = BASE_URL+uri
  url = "#{BASE_URL}"+CGI::escape(uri)
  f = File.open('response.log', 'a')
  start = Time.new
  f.print "#{start.to_s}\t#{uri}"
  resp = Net::HTTP.get_response(URI.parse(url))
  stop = Time.new
  f.puts "\t\t#{stop-start} seconds"
  f.close
  data = resp.body
  begin
    if data.blank? or data.include?('&lt;html')
      return {}
    end
    object = JSON.parse(data)
  rescue JSON::ParserError
    raise Exceptions::NothingReturned, "GET Error on #{raw_url}"
  end
  end
  </code></pre>