【发布时间】:2013-01-30 08:47:32
【问题描述】:
我正在尝试使用这篇文章:https://github.com/Licensario/licensario-rest-protocol/blob/master/rest-api.md#feature-usage
所以我写了:
## get request
feature_allocation_req = Net::HTTP::Get.new("/api/v1/users/external/#{user_id}/features/VIEW_TASKSed8e919e60/alloc?paymentPlanId=SUBSCRIPTI33dbf5e82a");
## add the headers
feature_allocation_req.add_field('ISV_API_KEY', 'bcffa3335a9068ab37ad51a68b4b47ea72f32a49c8f0b4f299a629edad04cdc3');
feature_allocation_req.add_field('ISV_API_SECRET', '14c990f3d4ee6354ee86fffdb057b3584f885c0d79cd3b354123e1b9acdc2227');
## start the get request
feature_allocation_result = nil
Net::HTTP.start("localhost", 3000) {|http|
feature_allocation_result = http.request(feature_allocation_req)
}
## print the number of the response (I got 200 - OK)
puts feature_allocation_result.code
## deserialize JSON objects
feature_allocation_parameters = Yajl::Parser.parse(feature_allocation_result.body);
total_parameter = feature_allocation_parameters["total"];
used_parameter = feature_allocation_parameters["used"];
available_parameter = feature_allocation_parameters["available"];
## print them
puts "***********************"
puts total_parameter, used_parameter, available_parameter
但它什么也没打印。我写错了什么吗? (我认为如果我有问题,问题是在“反序列化JSON对象”的步骤中发现的,但我尝试了:JSON.parse,它也不起作用)..
任何帮助表示赞赏。
【问题讨论】:
-
feature_allocation_result.body中有什么内容? -
每个值为空:{"total":null,"used":null,"available":null}
-
是的,所以问题在另一端。它向您发送 nil 值。
-
好的,所以你可以添加你的答案,我会标记它:] 谢谢!
标签: ruby-on-rails json rest protocols