UWP从json Url获取数组

时间:2017-10-13 12:59:31

标签: c# json uwp

我使用一个类从json获取数据到我的主页面,在我的json中我有一个数组我希望将它们带到我的主页面这里是我的类代码

    class WeatherDays
{
    public async static Task<day> GetWeather(double lat, double lon)
    {
        var http = new HttpClient();
        var responce = await http.GetAsync("http://a3ane.com/omarNasar/d.php");
        var result = await responce.Content.ReadAsStringAsync();
        var serializer = new DataContractJsonSerializer(typeof(day));

        var ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
        var data = (day)serializer.ReadObject(ms);
        return data;
    }
}
[DataContract]
public class Omarnasar
{
    [DataMember]
    public string w_id { get; set; }
    [DataMember]
    public string w_note_tody { get; set; }
    [DataMember]
    public string w_date { get; set; }
    [DataMember]
    public string w_time { get; set; }
    [DataMember]
    public string w_tody_one { get; set; }
    [DataMember]
    public string w_temperature_one { get; set; }
    [DataMember]
    public string w_humidity_one { get; set; }
    [DataMember]
    public string w_note_one { get; set; }
    [DataMember]
    public string w_tody_two { get; set; }
    [DataMember]
    public string w_temperature_two { get; set; }
    [DataMember]
    public string w_humidity_two { get; set; }
    [DataMember]
    public string w_note_two { get; set; }
    [DataMember]
    }
    [DataContract]
    public class day
    {
        [DataMember]
        public List<Omarnasar> omarnasar { get; set; }
    }
}

我的问题是我不知道如何使用此处的任务进入我的主页面我在MainPage上的尝试

        day week = await WeatherDays.GetWeather(20.0, 30.0);
        temp1.Text = week.omarnasr.

我不知道如何使用它们,任何人都可以帮助我!

1 个答案:

答案 0 :(得分:1)

我认为这就是你想要的

    StringBuilder sb = new StringBuilder();
    foreach(var obj in week.omarnasr)
    {
        sb.Append(obj.w_temperature_one + " ");
    }
    temp1.Text = sb.ToString();