开发者

Who is eating my \n

I send this json to my controller (as seen in my webrick log):

{\"repeatEveryYear\":\"TRUE\",\"scheduleTime\":\"2010-09-09T16:11:46Z\",\"message\":\"Hello World\n\nFirst test\"}

I dont know where all the escaping comes from, it is not something I add, and it seems rails eats it just fine?

My problem is that the second \n gets eaten some where in the process. Here is my controller that reads the json:

class SchedulesController < ApplicationController
  def create
    @schedule = Schedules.new.from_json(params[:schedule])
    @schedule.save
    render :json => "ok"
  end
end

Any ideas on what I can do to fix this?

Th开发者_开发技巧ank you


You might have to double-escape the newline characters:

{\"repeatEveryYear\":\"TRUE\",\"scheduleTime\":\"2010-09-09T16:11:46Z\",\"message\":\"Hello World\\n\\nFirst test\"}

This will convert each \\ to \ on the first pass (first decode) and then the \n to the newline on the 2nd pass (since it looks like it's a two-pass string).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜