Retrofit 2, same name different data type JSON Parsing

后端 未结 3 1434
时光取名叫无心
时光取名叫无心 2020-12-03 19:40

I am trying to parse a JSON response from a server, If there are changes to in the query sent in post method I will get first one as response, if not I will get the second o

3条回答
  •  -上瘾入骨i
    2020-12-03 20:09

    You cannot use like that. You have a status field in the response. Use the status filed to check for any data present. for example :

    if the status is 1:

    {
      "status": 1,
      "data": {
      "firstname": "First Name",
      "lastname": "Last Name",
      "mobilenumber": "1234567894",
      "emailid": "test@gmail.com",
      "timezone": "Asia/Kolkata"
    },
    "user_id": "",
    "response": "Profile Updated Successfully"
    }
    

    and if the status is 0 :

    {
      "status": 0,
      "data": {
      "firstname": "",
      "lastname": "",
      "mobilenumber": "",
      "emailid": "",
      "timezone": ""
    },
    "user_id": "",
    "response": "An error message"
    }
    

提交回复
热议问题