我有一個Ruby on rails源代碼,現在我想分析數據併發送數據。在我的代碼中,它將從中獲取名稱用戶並顯示它,如何解析ROR中的數據。如何從rails上解析json數據或(json代碼)
這是我controller.rb代碼
def index
@hotels = Hotel.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @hotels }
end
end
# GET /hotels/1
# GET /hotels/1.json
def show
@hotel = Hotel.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @hotel }
end
end
# GET /hotels/new
# GET /hotels/new.json
def new
@hotel = Hotel.new
respond_to do |format|
format.html # new.html.erb
format.json { render json: @hotel }
end
end
# GET /hotels/1/edit
def edit
@hotel = Hotel.find(params[:id])
end
# POST /hotels
# POST /hotels.json
def create
@hotel = Hotel.new(params[:hotel])
respond_to do |format|
if @hotel.save
format.html { redirect_to @hotel, notice: 'Hotel was successfully created.' }
format.json { render json: @hotel, status: :created, location: @hotel }
else
format.html { render action: "new" }
format.json { render json: @hotel.errors, status: :unprocessable_entity }
end
end
end
# PUT /hotels/1
# PUT /hotels/1.json
def update
@hotel = Hotel.find(params[:id])
respond_to do |format|
if @hotel.update_attributes(params[:hotel])
format.html { redirect_to @hotel, notice: 'Hotel was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @hotel.errors, status: :unprocessable_entity }
end
end
end
# DELETE /hotels/1
# DELETE /hotels/1.json
def destroy
@hotel = Hotel.find(params[:id])
@hotel.destroy
respond_to do |format|
format.html { redirect_to hotels_url }
format.json { head :no_content }
end
end
如何使用JSON 如何編寫解析這些數據的JSON文件來分析在ROR這些數據,如何做一個
你能爲我提供答案嗎?解決方案,我是新來的, – 2013-05-09 12:27:05
如何寫上述控制器的JSON文件,你可以給解決方案 – 2013-05-09 12:46:13
老兄這個答案是否足夠? – 2013-05-10 05:15:59