简体   繁体   English

改造嵌套Json对字符串的响应

[英]Retrofit nested Json response to string

I have a nested json response from my api like this: 我从我的api获得嵌套的json响应,如下所示:

{
    "notif_title":"Generic Notification",
    "notif_message":"you have a message",
    "url":"https://www.google.com",
    "set_profile":{
                   "54fdc8eb77761b8844e65f96":"1"
                  }
}

Problem 问题

The problem is that I want to get the set_profile json as a string no as an object because that object will be changing and I don't need to make any changes to it. 问题是我想将set_profile json作为字符串no作为对象来获取,因为该对象将发生变化,并且我不需要对其进行任何更改。

Question

Can I get that object as a string using retrofit?, thanks 我可以使用改型将该对象作为字符串吗?,谢谢

In retrofit if you want to parse JSON with dynamic keys (with dynamic names) you need to use HashMap for sure. 在改造中,如果要使用动态键(带有动态名称)解析JSON,则必须确保使用HashMap。

public class Name {
    @SerializedName("notif_title")
    @Expose
    private String notif_title;

    @SerializedName("notif_message")
    @Expose
    private String notif_message;

    @SerializedName("url")
    @Expose
    private String url;

    @SerializedName("set_profile")
    @Expose
    private Map<String, String> set_profile;
    //...setters and getters
}

hope this help 希望这个帮助

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

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