我將Ruby on Rails應用程序從3.0遷移到3.1,並遇到了JSON後端更改中的一些問題。在Ruby on Rails應用程序中設置json max_nesting選項
該行ActiveSupport::JSON.decode(some_variable)
給我MultiJson :: DecodeError nesting of 20 is too deep
。 我試圖解碼的變量實際上是嵌套的(最多29級)。
使用:max_nesting
選項('Nesting too deep' error while retrieving JSON using HTTParty)應該可以更改最大嵌套層次,但這似乎不起作用。
ActiveSupport::JSON.decode(some_variable, :max_nesting => false)
和ActiveSupport::JSON.decode(some_variable, :max_nesting => 100)
都會導致相同的錯誤。
有沒有辦法通過max_nesting
選項或將其設置爲應用程序範圍?
使用'JSON.parse(some_variable,:max_nesting => false)'解決了問題 – bmesuere