我想将id转换为要在url中使用的字符串
@tutorial_id = Demotutorial.where("job_id = ?", @job_id).select( "id")
@t_id = @tutorial_id.to_s
render json: @t_id
遇到此错误
SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data
教程Json数组
{"demotutorials":[{"demotutorials":{"id":50}}]}
答案 0 :(得分:1)
您的问题有两件事
下面是示例代码:
@tutorial_id = Demotutorial.where("job_id = ?", @job_id).select( "id").first
@t_id = @tutorial_id.id.to_s
render json: @t_id
答案 1 :(得分:0)
以下代码对我有用
@tutorial_id = Demotutorial.where("job_id = ?", @job_id).select( "id").first
@t_id = @tutorial_id[0].id.to_s
render json: @t_id