2011-06-30 54 views
2

以下两页提供了相同的JSON对象。是否有可能为我的rails应用程序使用Facebook Style JSON格式?更改JSON格式

所需的格式:

https://graph.facebook.com/19292868552 

我的应用程序格式:

http://sframework.heroku.com/api/graphs 

感谢

回答

5

红宝石JSON库具有pretty_generate功能。

require 'json' 
puts JSON.pretty_generate(fbJson) 
+0

DEF索引 文件=打开( “https://graph.facebook.com/19292868552”) @message = JSON.pretty_generate(file.read) respond_with(@message) 端 – glarkou

+0

这产生错误:2011-06-30T17:38:04 + 00:00 app [web.1]:JSON :: GeneratorError(仅允许生成JSON对象或数组): – glarkou

+0

@ntenisOT您可能需要先解析Facebook结果成JSON对象类似JSON.parse(file.read) – bkaid