繁体   English   中英

创建时出现Rails4 JSON参数解析错误

[英]Rails4 JSON Parameters Parse error while Create

我正在使用RoR构建适用于Android的API,正在获取用于从Android创建对象的参数,如下所示,

{"company"=>"{\"description\":\"Description of the company\",\"name\":\"Google\"}", "location"=>"Bangalore", "display_photo"=>#<ActionDispatch::Http::UploadedFile:0xb12dfa8 @tempfile=#<Tempfile:/tmp/RackMultipart20141119-6448-ewg4bk>, @original_filename="Male-Face-A1-icon.png", @content_type="image/*", @headers="Content-Disposition: form-data; name=\"display_photo\"; filename=\"Male-Face-A1-icon.png\"\r\nContent-Type: image/*\r\nContent-Length: 15460\r\nContent-Transfer-Encoding: binary\r\n">}

但是这一行在解析时给出了错误

"company"=>"{\"description\":\"Description of the company\",\"name\":\"Google\"}"

因为,Rails应该像这样,

"company"=>{"description":"Description of the company","name":"Google"}

如何在Rails中实现这一目标...

在Android请求Rails Server和Android Code的地方引用此链接

在您的参数中:

"company"=>

是一个哈希键

"{\"description\":\"Description of the company\",\"name\":\"Google\"}"

是一个字符串,哈希值

[2] pry(main)> JSON.parse "{\"description\":\"Description of the company\",\"name\":\"Google\"}"
=> {"description"=>"Description of the company", "name"=>"Google"}

提供正确的输出

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM