1
API를 사용하고 Amazon에서 일부 페이지 데이터를 추출하는 Kimonify를 시작했습니다. 보기에서 데이터는 @response
변수를 통해 전달됩니다.API 응답 구문 분석 방법 Kimonofy
어떻게 해석 할 수 있으며 Author Name
및 Rank
이 #22
일까요?
class HomeController < ApplicationController
def index
require 'rubygems'
require 'json'
require 'rest_client'
@response = RestClient.get 'https://www.kimonolabs.com/api/83x1k5ua?apikey=Gsj16resq87I8wRiaVjOrtzrs0WbAhZr'
end
end
index.html.erb
<h1>Home#index</h1>
<p>Find me in app/views/home/index.html.erb</p>
<p> <%= @response %> </p>
{ "name": "Tim Weed Sales Rank Colonial",
"count": 1,
"frequency":
"Every 15 mins",
"version": 11,
"newdata": true,
"lastrunstatus": "success",
"lastsuccess": "Tue Dec 23 2014 17:28:30 GMT+0000 (UTC)",
"thisversionstatus": "success",
"nextrun": "Tue Dec 23 2014 17:43:30 GMT+0000 (UTC)",
"results": { "Tim Weed Sales Rank Colonial": [ { "Title": "Will Poole's Island [Kindle Edition]",
"Colonial Historical Fiction Rank": "#22" } ]
}
}
JSON이 다시 표시되는 것처럼 보입니다. JSON을 구문 분석하는 방법을 배우려면이 게시물을 참조하십시오. http://stackoverflow.com/questions/1826727/how-do-i-parse-json-with-ruby-on-rails –
감사합니다 @ 닉. 이 기사는 또한 정말 도움이되었습니다. http://stackoverflow.com/questions/6284743/covert-json-string-to-json-array-in-rails – PatGW