Объект всегда пуст при десериализации на сервисе xamarin - PullRequest
0 голосов
/ 25 июня 2018

Построить этот сервис в приложении xamarin:

public class OpenWeatherMap<T>
{
    private const string OpenWeatherApi = "http://api.openweathermap.org/data/2.5/weather?q=";
    private const string Key = "653b1f0bf8a08686ac505ef6f05b94c2";

    HttpClient _httpClient = new HttpClient();

    // aqui podemos enviar directo a una ciudad hardcoded
    public async Task<T> GetAllWeathers(string city)
    {
        var json = await _httpClient.GetStringAsync(OpenWeatherApi + city + "&APPID=" + Key);
        var getWeatherModels = JsonConvert.DeserializeObject<T>(json);
        return getWeatherModels;
    }
}

Когда я проверяю, объект модели всегда пуст.JSON в порядке, и мой класс полностью соответствует моей модели JSON.Я использую Newtonsoft.Json.

Это моя модель:

public class WeatherMainModel
{

    [JsonProperty("coord")]
    public Coord Coord { get; set; }

    [JsonProperty("weather")]
    public WeatherSubDetails[] Weather { get; set; }

    [JsonProperty("base")]
    public string Base { get; set; }

    [JsonProperty("main")]
    public Main Main { get; set; }

    [JsonProperty("visibility")]
    public string Visibility { get; set; }

    [JsonProperty("wind")]
    public WeatherWindDetails Wind { get; set; }

    [JsonProperty("clouds")]
    public Clouds Clouds { get; set; }

    [JsonProperty("dt")]
    public string Dt { get; set; }

    [JsonProperty("sys")]
    public WeatherSysDetails Sys { get; set; }

    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("name")]
    public string Name { get; set; }

    [JsonProperty("cod")]
    public string Cod { get; set; }
}

public partial class Clouds // new
{
    [JsonProperty("all")]
    public string All { get; set; }
}

public partial class Coord // new
{
    [JsonProperty("lon")]
    public string Lon { get; set; }

    [JsonProperty("lat")]
    public string Lat { get; set; }
}

public partial class Main
{
    [JsonProperty("temp")]
    public string Temp { get; set; }

    [JsonProperty("pressure")]
    public string Pressure { get; set; }

    [JsonProperty("humidity")]
    public string Humidity { get; set; }

    [JsonProperty("temp_min")]
    public string TempMin { get; set; }

    [JsonProperty("temp_max")]
    public string TempMax { get; set; }
}

public partial class WeatherSysDetails
{
    [JsonProperty("type")]
    public string Type { get; set; }

    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("message")]
    public string Message { get; set; }

    [JsonProperty("country")]
    public string Country { get; set; }

    [JsonProperty("sunrise")]
    public string Sunrise { get; set; }

    [JsonProperty("sunset")]
    public string Sunset { get; set; }
}

public partial class WeatherSubDetails
{
    [JsonProperty("id")]
    public string Id { get; set; }

    [JsonProperty("main")]
    public string Main { get; set; }

    [JsonProperty("description")]
    public string Description { get; set; }

    [JsonProperty("icon")]
    public string Icon { get; set; }
}

public partial class WeatherWindDetails
{
    [JsonProperty("speed")]
    public string Speed { get; set; }

    [JsonProperty("deg")]
    public string Deg { get; set; }
}

Я использую сообщество Visual Studio, установленное для Латинской Америки (Чили), поэтому я попытался изменить каждое десятичное полена JSON, чтобы связать модель, чтобы избежать проблем с разделением запятыми, но мой объект становится пустым независимо от того, какой JSON я внедряю в десериализатор.Заранее спасибо.

...