我正在尝试将JSON从URL转换为R中的CSV / data.frame。数据位于:Data_Kayak并粘贴在下方。
到目前为止,我已尝试newJSONParser()
中的fromJSON
和library(rjson)
。我已经足够接近生成一个列表,但这是我迄今为止所做的最好的。我需要CSV格式,以便我可以分析和绘制它。
{"origin":{"latitude":37.25,"name":"Springfield, MO","shortName":"SGF","longitude":-93.38333333},"destinations":[{"country":{"latitude":40,"name":"United States","shortName":"US","longitude":-96.5},"flight":359,"temp":[[18,43],[21,46],[28,54],[36,61],[45,72],[54,82],[59,88],[57,86],[48,77],[37,64],[25,52],[18,45]],"flightInfo":{"price":359},"languages":["en"],"city":{"latitude":39.73917,"name":"Denver","id":"12493","longitude":-104.98417},"shortDateRange":"2/28 - 3/8","airport":{"latitude":39.86310781,"popularity":40614,"name":"Denver, CO","shortName":"DEN","longitude":-104.6748161},"flightMaxDuration":135,"activities":["ski","gambling","golf"],"days":8,"region":{"latitude":39.149496257664,"name":"Colorado","shortName":"CO","longitude":-104.94804819074001},"depart":"20150228","airline":"United","return":"20150308","flightMaxStops":0},{"country":{"latitude":40,"name":"United States","shortName":"US","longitude":-96.5},"flight":279,"temp":[[16,32],[19,36],[28,46],[39,59],[48,70],[57,79],[63,84],[63,82],[54,75],[43,63],[32,48],[21,36]],"flightInfo":{"price":279},"languages":["en"],"city":{"latitude":41.88451,"name":"Chicago","id":"12514","longitude":-87.63095},"shortDateRange":"2/19 - 2/28","airport":{"latitude":41.98333333,"popularity":32415,"name":"Chicago, IL","shortName":"ORD","longitude":-87.9},"flightMaxDuration":90,"activities":["ski","gambling","golf"],"days":9,"region":{"latitude":40.268763621091,"name":"Illinois","shortName":"IL","longitude":-89.062810958234},"depart":"20150219","airline":"American Airlines","return":"20150228","flightMaxStops":0},{"country":{"latitude":40,"name":"United States","shortName":"US","longitude":-96.5},"flight":379,"temp":[[34,52],[37,57],[45,66],[52,73],[61,81],[68,86],[72,90],[70,88],[64,82],[54,73],[43,64],[36,55]],"flightInfo":{"price":379},"languages":["en"],"city":{"latitude":33.74889,"name":"Atlanta","id":"11123","longitude":-84.38806},"shortDateRange":"2/27 - 3/1","airport":{"latitude":33.65,"popularity":30080,"name":"Atlanta, GA","shortName":"ATL","longitude":-84.43333333},"flightMaxDuration":120,"activities":["golf"],"days":2,"region":{"latitude":32.929258844272,"name":"Georgia","shortName":"GA","longitude":-83.621524741888},"depart":"20150227","airline":"Delta","return":"20150301","flightMaxStops":0},{"country":{"latitude":40,"name":"United States","shortName":"US","longitude":-96.5},"flight":279,"temp":[[36,55],[39,61],[48,68],[55,77],[64,84],[72,91],[75,97],[75,95],[68,88],[57,79],[46,66],[37,57]],"flightInfo":{"price":279},"languages":["en"],"city":{"latitude":32.78333,"name":"Dallas","id":"16406","longitude":-96.8},"shortDateRange":"2/25 - 3/3","airport":{"latitude":32.89710131,"popularity":24500,"name":"Dallas, TX","shortName":"DFW","longitude":-97.04386711},"flightMaxDuration":90,"activities":["golf"],"days":6,"region":{"latitude":31.344670987137,"name":"Texas","shortName":"TX","longitude":-97.666193354857},"depart":"20150225","airline":"American Airlines","return":"20150303","flightMaxStops":0}]}
答案 0 :(得分:0)
jsonlite做了这个伎俩
library(jsonlite)
library("RCurl", lib.loc="~/R/win-library/3.1")
setwd("~/Kayak R")
url <- "http://www.kayak.com/h/explore/api?airport=SGF&v=1&flightMaxStops=0"
kkjson <- getURLContent(url)
kk_txt_from_json <- fromJSON(kkjson)
kk_table = data.frame(kk_txt_from_json)