V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
michaelye1988
V2EX  ›  问与答

使用 Gson 将 json 数据转为 bean 对象失败

  •  
  •   michaelye1988 · Feb 21, 2014 · 3498 views
    This topic created in 4454 days ago, the information mentioned may be changed or developed.
    {"weatherinfo":{"city":"福州","cityid":"101230101","temp":"14","WD":"东南风","WS":"1级","SD":"39%","WSE":"1","time":"15:30","isRadar":"1","Radar":"JC_RADAR_AZ9591_JB"}}



    //转换方法

    WeatherInfo weatherInfo = gson.fromJson(response, WeatherInfo.class);

    public class WeatherInfo
    {
    private RealTimeWeather realWeather;
    }

    public class RealTimeWeather
    {

    private String city;
    private String cityid;
    private String temp;
    private String WD;
    private String WS;
    private String SD;
    private String WSE;
    private String time;
    private String isRadar;
    private String Radar;
    }


    有人能看出问题吗?
    2 replies    1970-01-01 08:00:00 +08:00
    zhouquanbest
        1
    zhouquanbest  
       Feb 21, 2014   ❤️ 1
    改成
    @SerializedName("weatherinfo")
    private RealTimeWeather realWeather;
    试试
    michaelye1988
        2
    michaelye1988  
    OP
       Feb 21, 2014
    @zhouquanbest 果然!谢谢~
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2371 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 31ms · UTC 05:54 · PVG 13:54 · LAX 22:54 · JFK 01:54
    ♥ Do have faith in what you're doing.