Java,使用多个数据发送POST请求,并使用Gson解析JSON响应

时间:2018-11-29 09:49:18

标签: java json post gson http-post

我正在寻找以下方面的帮助

任务:将POST请求发送到https://test.example.com/booking/(例如,链接是伪造的) 请求包含:

•标头:

Content-Type: application/json

•身体:

{
  "segments": [
    {
      "brand": "EL",
      "flight_number": "0149",
      "booking_class": "N",
      "departure_date": "2018-11-28 01:50",
      "destination": "PRG",
      "origin": "BCN",
      "marriage_group": "",
      "airline_code": "TS"
    }
  ],
  "passengers": [
    {
      "pax_type": "ADULT",
      "first_name": "ADULT",
      "patronymic": "",
      "last_name": "TEST",
      "birthdate": "1980-01-03",
      "sex": "M",
      "nationality": "EE",
      "doc_type": "PASSPORT",
      "doc_country": "EE",
      "doc_expiration": "2020-01-01",
      "doc_number": "123654789",
      "loyalty_program": "TS",
      "loyalty_id": "",
      "special_services": [],
      "is_fan": false,
      "fan_id": null
    }
  ],
  "country": "EE",
  "phone": "7123654789",
  "email": "test@test.ee",
  "email_lang": "en",
  "lang": "en",
  "coupon_codes": [],
  "extra": {},
  "client": {
    "ga_client_id": "",
    "loyalty_id": ""
  }
}

作为答复,我将收到:

{
    "data": {
        "payment_url": "https://test.example.com/booking/roduct=SBWEB&PNR=DXZZLX&language=EE&sign=5a0882c1996e926ae46fcb8c595dd749",
        "pnr_key": "73fa087e0d7490fd2c11ef362a2c00ac37878bf7d49416915f3f2d60b4edc7d267747886cc4084590b1673c65368f38a6a6ad0cde856d688d1d7aa784d42f3c0",
        "pnr_locator": "DXZZLX"
    },
    "error": null,
    "success": true
}

从响应中,我只需要“ pnr_locator”:“ DXZZLX”

问题:

1。。我看到了许多关于stackoverflow的主题,但是其中大多数是4年前发布的。自那时以来,已经发布了许多更新和有用的库,因此,如果有人可以分享现代链接或建议,我将不胜感激。例如,据我所知,我应该使用OkHttp(用于连接)和Gson(用于Json解析),对吗?

2。。我需要为此任务创建多少个类?在这种情况下,我需要使用序列化吗?

0 个答案:

没有答案