简体   繁体   English

如何使用 Android 中的 retrofit 从这种类型的 JSON 响应中获取数据

[英]How to get data from this type of JSON response using retrofit in Android

This is JSON response:这是 JSON 响应:

    {
        "0": {
            "userId": "8888888888",
            "Long": "77.28717",
            "Lat": "28.63864",
            "time": "14:14:47",
            "date": "2020-12-19"
        },
        "1": {
            "userId": "8888888888",
            "Long": "77.28141",
            "Lat": "28.63602",
            "time": "14:10:05",
            "date": "2020-12-19"
        },
        "2": {
            "userId": "8888888888",
            "Long": "77.28716",
            "Lat": "28.63863",
            "time": "14:09:40",
            "date": "2020-12-19"
        },
        "status": "success"
    }

Retrofit Retrofit

This can help you.这可以帮助你。 You have to try.你得试试。

here is a link for create pojo class for retrofit response.这是为 retrofit 响应创建 pojo class 的链接。 create here your class.在此处创建您的 class。

  1. paste your response here and select other option you want like serializable, parcalble etc.在此处粘贴您的回复和 select 您想要的其他选项,如可序列化、可解析等。
  2. then give your package name and class name.然后给出您的 package 名称和 class 名称。
  3. then download zip from there and add to your project.然后从那里下载 zip 并添加到您的项目中。

here is example for your class.这是您的 class 的示例。

这是您班级的示例。

Here is full example for calling API through retrofit. 这是通过 retrofit 调用 API 的完整示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM