Convert string into Array in rails

后端 未结 3 631
渐次进展
渐次进展 2020-12-10 03:01

I send an array from rest client and received it like this: \"[1,2,3,4,5]\"

Now I just want to convert it into Array without using Ruby\'s eval

3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-10 03:54

    require 'json'
    
    JSON.parse "[1,2,3,4,5]"
      #=> [1, 2, 3, 4, 5] 
    
    JSON.parse "[[1,2],3,4]"
      #=> [[1, 2], 3, 4] 
    

提交回复
热议问题