2012-08-16 82 views
0

我在Rails 3中編寫了一個API供iOS應用讀取。作爲字典的Rails JSON

我寫了這個:

def index 
    @shops = Shop.all 

    render json: @shops 
end 

輸出出來作爲一個磁盤陣列:

[{ 
"created_at": "2012-07-28T10:35:38Z", 
"id": 1, 
"name": "Shop1", 
"phone": "111-111-1111", 
"updated_at": "2012-07-28T10:35:38Z" 
}] 

不過,我想我的iOS應用程序讀取它作爲一個字典

哪有我把JSON輸出轉換成字典?

+0

您想要什麼樣的結果?它應該是像「{」shops「:[{」created_at「:...}]}這樣的字典,或者其他不同的東西? – Veraticus 2012-08-16 15:06:11

+0

是的,完全是這樣的字典。 – Castielle 2012-08-16 15:06:52

回答

0

我環顧了一下,但不幸的是無法自動找到這樣做的方法。目前,您最好的選擇可能是手動完成這項工作:

def index 
    @shops = Shop.all 

    render json: {:shops => @shops} 
end 
+0

工作,謝謝! – Castielle 2012-08-16 15:46:49