2011-06-30 184 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