2016-02-25 93 views
0

我有一個ruby json對象。例如如何將"轉換爲double qoutes

在控制器

@my_hash = {"5":{"id":5,"name":"ANKLOS","code":"724.9","description":"Ankylosis of spine (Spine Fusion)","title":"ANKLOS - 724.9 - Ankylosis of spine (Spine Fusion)"},"3":{"id":3,"name":"Loren Lipsum","code":"Test","description":"Test t2 stest","title":"Loren Lipsum - Test - Test t2 stest"}} 

我用@my_hash在視圖中。我的內容是從表中動態獲得的。

<script type="text/javascript"> 
    var my_hash = <%= @my_hash.to_json %>; 
</script> 

但my_hash的結果就像

var diagnosisCodes = {&quot;&quot;:{&quot;code&quot;:&quot;\u0026larr;&quot;,&quot;description&quot;:&quot;&quot;},&quot;5&quot;:{&quot;id&quot;:5,&quot;name&quot;:&quot;ANKLOS&quot;,&quot;code&quot;:&quot;724.9&quot;,&quot;description&quot;:&quot;Ankylosis of spine (Spine Fusion)&quot;,&quot;title&quot;:&quot;ANKLOS - 724.9 - Ankylosis of spine (Spine Fusion)&quot;},&quot;3&quot;:{&quot;id&quot;:3,&quot;name&quot;:&quot;Loren Lipsum&quot;,&quot;code&quot;:&quot;Test&quot;,&quot;description&quot;:&quot;Test t2 stest&quot;,&quot;title&quot;:&quot;Loren Lipsum - Test - Test t2 stest&quot;}}; 

我需要輸出同樣喜歡@my_hash。我怎樣才能做到這一點?

回答