我正在研究一个示例 Ruby / Grape 示例,除了 json 被转义之外,一切正常。我也是全新的 ruby 及其框架(仅 3 天),很抱歉,如果这个问题是补救性的,并提前谢谢你
我相当肯定不应该转义引号,无论如何这里是转义的输出:
"{\"word\":\"test\",\"sentiment\":\"unkown\"}"
我的代码
require 'rubygems'
require 'grape'
require 'json'
class SentimentApiV1 < Grape::API
version 'v1', :using => :path, :vendor => '3scale'
format :json
resource :words do
get ':word' do
{:word => params[:word], :sentiment => "unkown"}.to_json
end
post ':word' do
{:word => params[:word], :result => "thinking"}.to_json
end
end
resource :sentences do
get ':sentence' do
{:sentence => params[:sentence], :result => "unkown"}.to_json
end
end
end
配置.ru
$:.unshift "./app"
需要'sentimentapi_v1.rb'
运行 SentimentApiV1
包和版本
C:\Ruby-Projects\GrapeTest>bundle install
Using i18n (0.6.4)
Using minitest (4.7.5)
Using multi_json (1.7.7)
Using atomic (1.1.10)
Using thread_safe (0.1.0)
Using tzinfo (0.3.37)
Using activesupport (4.0.0)
Using backports (3.3.3)
Using builder (3.2.2)
Using daemons (1.1.9)
Using descendants_tracker (0.0.1)
Using hashie (2.0.5)
Using multi_xml (0.5.4)
Using rack (1.5.2)
Using rack-accept (0.4.5)
Using rack-mount (0.8.3)
Using virtus (0.5.5)
Using grape (0.5.0)
Using json (1.8.0)
Using thin (1.5.1)
Using bundler (1.3.5)
我正在运行 ruby 2.0、grape .5、windows 8 64bit