[英]I have a JSON object in my Controller (Ruby/Rails) but i want to access the Json's Object attributes. How to do that
[英]How do I access my json data that I have created in rails
我可以输入什么URL来查看json值以及如何让我的iphone项目访问它。
这是我的索引方法
def index
@players = Player.find(:all)
respond_to do |format|
format.html
format.json { render :json => @players.to_json }
end
end
这是我的路线。
ChooseTeams::Application.routes.draw do
resources :players
root :to => "players#index"
end
请询问任何其他信息,因为我是rails的新手,不知道还有什么可以提供。
索引方法:localhost :( port)/players.json(Method GET)
显示方法:localhost :( port)/players/1.json(Method GET)
我建议您使用POSTMAN(在Google Chrome中)测试此响应。
要响应iPhone JSON,请使用REST API
您应该在请求URL时设置接受标头:
curl -H 'Accept: application/json' http://localhost:<PORT>/players
在您的iOS项目中,您应该设置您正在使用的任何HTTP库来设置上面的标题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.