RIS JSON API内容压缩

发布于 2025-02-02 16:53:55 字数 2572 浏览 3 评论 0 原文

我正在尝试使用德国铁路的RIS API。我设法在似乎是JSON的时间表上使用了一个。 https://developers.deutschebahn.com/db-api-marketplace/apis/product/fahrplan/api/9213#/Fahrplan_101/operation/%2Flocation%2F{name}/get

GET https://apis.deutschebahn.com/db-api-marketplace/apis/fahrplan/v1/location/Berlin
Header:
Accept: application/json
DB-Client-Id: 36fd91806420e2e937a599478a557e06
DB-Api-Key: d8a52f0f66184d80bdbd3a4a30c0cc33

Which using httr 我可以复制:

url_location<-"https://apis.deutschebahn.com/db-api-marketplace/apis/fahrplan/v1/location/Bonn"
r<-GET(url_location, 
       add_headers(Accept="application/json",
                   `DB-Client-Id` = client_id, 
                   `DB-Api-Key` = api_key))
content(r)

我知道要使用另一个有关电台的API。 https://developers.deutschebahn.com/db-papi-marketplace/apis/product/ris-stations/ris-stations/api/ris-stations#/risstations/risstations_160/operation/poperation/poperation/%2fstations/get

GET https://apis.deutschebahn.com/db-api-marketplace/apis/ris-stations/v1/stations?onlyActive=true&limit=100
Header:
  Accept: application/vnd.de.db.ris+json
DB-Client-Id: 36fd91806420e2e937a599478a557e06
DB-Api-Key: d8a52f0f66184d80bdbd3a4a30c0cc33

我希望我希望这样做只需调整接受

url_station<-"https://apis.deutschebahn.com/db-api-marketplace/apis/ris-stations/v1/stations?onlyActive=true&limit=100"
r_stations<-GET(url_station, 
               add_headers(Accept="application/vnd.de.db.ris+json",
                           `DB-Client-Id` = client_id, 
                           `DB-Api-Key` = api_key))

我收到一些数据,状态代码为200

content 函数或没有它,我得到以下内容

> head(content(r_stations), 30)
 [1] 7b 22 6f 66 66 73 65 74 22 3a 30 2c 22 6c 69 6d 69 74 22 3a 31 30 30 2c 22 74 6f 74 61 6c

r_stations$status_code
[1] 200

,我应该得到更多这样的东西:

{
  "offset": 0,
  "limit": 100,
  "total": 5691,
  "stations": [
    {
      "stationID": "1",
      "names": {
        "DE": {
          "name": "Aachen Hbf"
        }
      },

I am trying to use the RIS API from the german railway. I managed to use the one on timetables that seems to be json.
https://developers.deutschebahn.com/db-api-marketplace/apis/product/fahrplan/api/9213#/Fahrplan_101/operation/%2Flocation%2F{name}/get

GET https://apis.deutschebahn.com/db-api-marketplace/apis/fahrplan/v1/location/Berlin
Header:
Accept: application/json
DB-Client-Id: 36fd91806420e2e937a599478a557e06
DB-Api-Key: d8a52f0f66184d80bdbd3a4a30c0cc33

Which using httr I can replicate:

url_location<-"https://apis.deutschebahn.com/db-api-marketplace/apis/fahrplan/v1/location/Bonn"
r<-GET(url_location, 
       add_headers(Accept="application/json",
                   `DB-Client-Id` = client_id, 
                   `DB-Api-Key` = api_key))
content(r)

I know want to use another API about stations.
https://developers.deutschebahn.com/db-api-marketplace/apis/product/ris-stations/api/ris-stations#/RISStations_160/operation/%2Fstations/get

GET https://apis.deutschebahn.com/db-api-marketplace/apis/ris-stations/v1/stations?onlyActive=true&limit=100
Header:
  Accept: application/vnd.de.db.ris+json
DB-Client-Id: 36fd91806420e2e937a599478a557e06
DB-Api-Key: d8a52f0f66184d80bdbd3a4a30c0cc33

I was hoping that it would work as well just adjusting the Accept:

url_station<-"https://apis.deutschebahn.com/db-api-marketplace/apis/ris-stations/v1/stations?onlyActive=true&limit=100"
r_stations<-GET(url_station, 
               add_headers(Accept="application/vnd.de.db.ris+json",
                           `DB-Client-Id` = client_id, 
                           `DB-Api-Key` = api_key))

I recieve some data and the status code is 200. It was 415 before adjusting the Accept

When I am looking at the content using the content function or without it I get the following

> head(content(r_stations), 30)
 [1] 7b 22 6f 66 66 73 65 74 22 3a 30 2c 22 6c 69 6d 69 74 22 3a 31 30 30 2c 22 74 6f 74 61 6c

r_stations$status_code
[1] 200

I should get something more like this:

{
  "offset": 0,
  "limit": 100,
  "total": 5691,
  "stations": [
    {
      "stationID": "1",
      "names": {
        "DE": {
          "name": "Aachen Hbf"
        }
      },

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断桥再见 2025-02-09 16:53:55

我只需要添加 type ='application/json'

content(r_stations, type='application/json')

I just need to add type='application/json'

content(r_stations, type='application/json')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文