Ios 在带有Monotouch的UITableView上加载JSON
我正在使用Xamarin.iOS返回JSON并尝试将其放置在UITableView上,但是我正在覆盖Instagram客户端类中数据类中的Ios 在带有Monotouch的UITableView上加载JSON,ios,json,uitableview,xamarin.ios,xamarin,Ios,Json,Uitableview,Xamarin.ios,Xamarin,我正在使用Xamarin.iOS返回JSON并尝试将其放置在UITableView上,但是我正在覆盖Instagram客户端类中数据类中的ToString(),我希望能够修复此问题,以便加载的不仅仅是它们的名称 以下是将JSON转换为类对象的Instagram客户端: public class RootObject { public Pagination pagination { get; set; } public Meta meta { get; set; } pub
ToString()
,我希望能够修复此问题,以便加载的不仅仅是它们的名称
以下是将JSON转换为类对象的Instagram客户端:
public class RootObject
{
public Pagination pagination { get; set; }
public Meta meta { get; set; }
public List<Datum> data { get; set; }
}
public class Datum
{
public object attribution { get; set; }
public List<string> tags { get; set; }
public string type { get; set; }
public object location { get; set; }
public Comments comments { get; set; }
public string filter { get; set; }
public string created_time { get; set; }
public string link { get; set; }
public Likes likes { get; set; }
public Images images { get; set; }
public List<object> users_in_photo { get; set; }
public Caption caption { get; set; }
public bool user_has_liked { get; set; }
public string id { get; set; }
public User user { get; set; }
public Videos videos { get; set; }
// This is the Overridden method I want to get rid of
public override string ToString()
{
if (user == null)
{
return "User is null";
}
return user.full_name;
}
}
public class Videos
{
public LowResolution2 low_resolution { get; set; }
public StandardResolution2 standard_resolution { get; set; }
}
public class StandardResolution2
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
public class LowResolution2
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
public class User
{
public string username { get; set; }
public string website { get; set; }
public string profile_picture { get; set; }
public string full_name { get; set; }
public string bio { get; set; }
public string id { get; set; }
}
public class Caption
{
public string created_time { get; set; }
public string text { get; set; }
public From from { get; set; }
public string id { get; set; }
}
public class From
{
public string username { get; set; }
public string profile_picture { get; set; }
public string id { get; set; }
public string full_name { get; set; }
}
public class Images
{
public LowResolution low_resolution { get; set; }
public Thumbnail thumbnail { get; set; }
public StandardResolution standard_resolution { get; set; }
}
public class StandardResolution
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
public class Thumbnail
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
public class LowResolution
{
public string url { get; set; }
public int width { get; set; }
public int height { get; set; }
}
public class Likes
{
public int count { get; set; }
public List<Datum2> data { get; set; }
}
public class Datum2
{
public string username { get; set; }
public string profile_picture { get; set; }
public string id { get; set; }
public string full_name { get; set; }
}
public class Comments
{
public int count { get; set; }
public List<object> data { get; set; }
}
public class Meta
{
public int code { get; set; }
}
public class Pagination
{
public string next_url { get; set; }
public string next_max_id { get; set; }
}
公共类根对象
{
公共分页分页{get;set;}
公共元{get;set;}
公共列表数据{get;set;}
}
公共类数据
{
公共对象属性{get;set;}
公共列表标记{get;set;}
公共字符串类型{get;set;}
公共对象位置{get;set;}
公共评论{get;set;}
公共字符串筛选器{get;set;}
创建的公共字符串\u time{get;set;}
公共字符串链接{get;set;}
公众喜欢{get;set;}
公共图像图像{get;set;}
公共列表用户在照片{get;set;}
公共标题标题{get;set;}
公共bool用户_喜欢{get;set;}
公共字符串id{get;set;}
公共用户{get;set;}
公共视频{get;set;}
//这是我想要摆脱的重写方法
公共重写字符串ToString()
{
if(user==null)
{
返回“用户为空”;
}
返回user.full_名称;
}
}
公开课视频
{
公共低分辨率2低分辨率{get;set;}
公共标准解析2标准_解析{get;set;}
}
公共类标准解决方案2
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公共类低分辨率2
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公共类用户
{
公共字符串用户名{get;set;}
公共字符串网站{get;set;}
公共字符串配置文件\u图片{get;set;}
公共字符串全名{get;set;}
公共字符串bio{get;set;}
公共字符串id{get;set;}
}
公共类标题
{
创建的公共字符串\u time{get;set;}
公共字符串文本{get;set;}
来自{get;set;}的公共
公共字符串id{get;set;}
}
公共课
{
公共字符串用户名{get;set;}
公共字符串配置文件\u图片{get;set;}
公共字符串id{get;set;}
公共字符串全名{get;set;}
}
公众阶级形象
{
公共低分辨率低分辨率{get;set;}
公共缩略图{get;set;}
公共标准解析标准_解析{get;set;}
}
公共类标准解析
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公共类缩略图
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公共类低分辨率
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公众阶级喜欢
{
公共整数计数{get;set;}
公共列表数据{get;set;}
}
公共类数据2
{
公共字符串用户名{get;set;}
公共字符串配置文件\u图片{get;set;}
公共字符串id{get;set;}
公共字符串全名{get;set;}
}
公开课评论
{
公共整数计数{get;set;}
公共列表数据{get;set;}
}
公共类元
{
公共整数代码{get;set;}
}
公共类分页
{
公共字符串next_url{get;set;}
公共字符串next_max_id{get;set;}
}
主视图控制器
这就是我返回JSON的方式
var request = new RestRequest { RootElement = "data", Resource = "/users/self/feed" };
request.AddParameter ("access_token", instagramAccessToken);
var client = new RestClient ("https://api.instagram.com/v1");
client.ExecuteAsync (request, response => {
var rootObject = JsonConvert.DeserializeObject<RootObject> (response.Content);
table.InvokeOnMainThread (() => {
table.Source = new TableSource<Datum>(rootObject.data);
table.ReloadData ();
});
}
);
var request=new RestRequest{RootElement=“data”,Resource=“/users/self/feed”};
request.AddParameter(“访问令牌”,instagramAccessToken);
var client=新的RestClient(“https://api.instagram.com/v1");
client.ExecuteAsync(请求、响应=>{
var rootObject=JsonConvert.DeserializeObject(response.Content);
table.InvokeOnMainThread(()=>{
table.Source=新表源(rootObject.data);
table.ReloadData();
});
}
);
表源类
public List<T> Data { get; set; }
protected string cellIdentifier = "TableCell";
public TableSource ()
{
Data = new List<T> ();
}
public TableSource(List<T> data)
{
Data = data;
}
public override int RowsInSection (UITableView tableview, int section)
{
return Data.Count;
}
public override void RowSelected (UITableView tableView, NSIndexPath indexPath)
{
if (OnRowSelected != null) {
OnRowSelected (this, new RowSelectedEventArgs (tableView, indexPath));
}
}
public class RowSelectedEventArgs : EventArgs
{
public UITableView tableView { get; set; }
public NSIndexPath indexPath { get; set; }
public RowSelectedEventArgs(UITableView tableView, NSIndexPath indexPath) : base()
{
this.tableView = tableView;
this.indexPath = indexPath;
}
}
public event EventHandler<RowSelectedEventArgs> OnRowSelected;
public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath)
{
if (tableView.ContentSize.Height - UIScreen.MainScreen.Bounds.Height <= tableView.ContentOffset.Y) {
// this is the last row in the last section
Console.WriteLine ("~~~Bottom~~~");
}
UITableViewCell cell = tableView.DequeueReusableCell (cellIdentifier);
// if there are no cells to reuse, create a new one
if (cell == null)
cell = new UITableViewCell (UITableViewCellStyle.Default, cellIdentifier);
// Edited Text
cell.TextLabel.Text = Data[indexPath.Row].ToString ();
return cell;
}
公共列表数据{get;set;}
受保护的字符串cellIdentifier=“TableCell”;
公共表源()
{
数据=新列表();
}
公共表源(列表数据)
{
数据=数据;
}
公共覆盖int RowsInSection(UITableView表格视图,int section)
{
返回数据。计数;
}
public override void RowSelected(UITableView tableView,NSIndexPath indexPath)
{
如果(OnRowSelected!=null){
OnRowSelected(此,新行SelectedEventArgs(tableView,indexPath));
}
}
公共类行SelectedEventArgs:EventArgs
{
公共UITableView表视图{get;set;}
公共NSIndexPath索引XPath{get;set;}
公共行SelectedEventArgs(UITableView tableView,NSIndexPath indexPath):base()
{
this.tableView=tableView;
this.indepath=indepath;
}
}
已选择公共事件事件处理程序OnRowHandler;
公共覆盖UITableViewCell GetCell(UITababVIEW TabLVIEW,MyLux.Posial.NSIXDEXPATH索引路径)
{
如果(tableView.ContentSize.Height-UIScreen.MainScreen.Bounds.Height在GetCell方法中,可以访问数据的任何属性。如果要显示两行以上的数据,可能需要创建自定义UITableViewCell
var item = Data[indexPath.Row];
cell.TextLabel.Text = item.User.username + " (" + item.User.full_name + ")";
cell.DetailTextLabel.Text = "Created at: " + item.created_time;
问题是,我的表源中定义的数据列表具有对象类型而不是数据,因此我无法执行您的建议。我还希望将其保留为公共列表数据而不是公共列表数据,因为我希望能够为