我有来自“http://www.football-data.org/soccerseasons/的以下Json数据 这是我到目前为止的代码,我想添加“items = resp [i] .caption();”到listview和im stuggling,因为这是我的第一个android项目,我习惯了windows listitems.add
System.Collections.Generic.List<SportsRadio.seasons.RootObject> list = new System.Collections.Generic.List<SportsRadio.seasons.RootObject>();
String[] items;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
var client = new RestClient() { BaseUrl = new Uri("http://www.football-data.org/soccerseasons/") };
var request = new RestRequest() { Resource = "", Method = Method.GET, RequestFormat = DataFormat.Json };
client.ExecuteAsync(request, (response, handle) =>
{
RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();
var resp = deserial.Deserialize<List<SportsRadio.seasons.RootObject>>(response);
string json = response.Content;
for (int i = 0; i < json.Length; i++)
{
items[i] = resp[i].caption;
}
ListAdapter = new ArrayAdapter<String>(this, Android.Resource.Layout.SimpleListItem1, items);
});
namespace SportsRadio.seasons
{
public class RootObject
{
public int id { get; set; }
public string caption { get; set; }
public string league { get; set; }
public string year { get; set; }
public string lastUpdated { get; set; }
}
}
我使用Json2Csharp
创建了这个类