I have the class "Alerts", which contains some returned information from Wunderground's API. I then have another class inside "Alerts", "Alert". My code looks like this:
public class Alerts
{
public class Features
{
public int alerts { get; set; }
}
public class Response
{
public string version { get; set; }
public string termsofService { get; set; }
public Features features { get; set; }
}
public class ZONED
{
public string state { get; set; }
public string ZONE { get; set; }
}
public class StormBased
{
}
public class Alert
{
public string type { get; set; }
public string description { get; set; }
public string date { get; set; }
public string date_epoch { get; set; }
public string expires { get; set; }
public string expires_epoch { get; set; }
public string message { get; set; }
public string phenomena { get; set; }
public string significance { get; set; }
public List<ZONED> ZONES { get; set; }
public StormBased StormBased { get; set; }
}
public class RootObject
{
public Response response { get; set; }
public string query_zone { get; set; }
public List<Alert> alerts { get; set; }
}
public class AlertsUpdateState
{
public HttpWebRequest AsyncRequest { get; set; }
public HttpWebResponse AsyncResponse { get; set; }
}
}
I create a RootObject when the app starts, and later use JSON to empty values. The call returns "response", "query_zone", and "alerts". Now the last one is a List of type Alert, which contains type, description, etc. of an issued alert.
So I have this list stored as alertVar. This has several methods, including count. I can figure out how many alerts are issued, but I'm not sure how to move on.
How do I retrieve the string values (such as type) with this list?
Assuming alertVar
is your list of Alert
, you can do something like:
string some_string;
foreach (var alert in alertVar)
{
some_string += alert.type + ", ";
}
This will add all the types to a long string (some_string
).
You can do the same for whichever property you want ...