C# 如何在活动之间传递对象

C# 如何在活动之间传递对象,c#,android,object,android-activity,xamarin,C#,Android,Object,Android Activity,Xamarin,我有一个feed对象,其中填充了反序列化的json数据。我试图在两个xamarin android活动之间传递一个提要对象 我怎样才能做到这一点 我知道putseriazable,但我不知道如何实现它 public class Feed { public class Author { public int id { get; set; } public string slug { get; set; } public string

我有一个feed对象,其中填充了反序列化的json数据。我试图在两个xamarin android活动之间传递一个提要对象

我怎样才能做到这一点

我知道putseriazable,但我不知道如何实现它

public class Feed
{
    public class Author
    {
        public int id { get; set; }
        public string slug { get; set; }
        public string name { get; set; }
        public string first_name { get; set; }
        public string last_name { get; set; }
        public string nickname { get; set; }
        public string url { get; set; }
        public string description { get; set; }
    }       

    public class CustomFields
    {
        public List<string> sno_headline { get; set; }
        public List<string> sno_deck { get; set; }
        public List<string> sno_format { get; set; }
        public List<string> sno_longform_order { get; set; }
        public List<string> sno_longform_title { get; set; }
        public List<string> sno_sr_tag { get; set; }
        public List<string> sno_sr_cat { get; set; }
        public List<string> sno_sr_title { get; set; }
        public List<string> sno_longform_main_title { get; set; }
        public List<string> sno_rails_number { get; set; }
        public List<string> sno_rails_writer { get; set; }
        public List<string> sno_rails_type { get; set; }
        public List<string> sno_rails_stories { get; set; }
        public List<string> sno_longform_image { get; set; }
        public List<string> sno_longform_image_master { get; set; }
        public List<string> sno_teaser { get; set; }
        public List<string> writer { get; set; }
        public List<string> jobtitle { get; set; }
        public List<string> featureimage { get; set; }
        public List<string> video { get; set; }
        public List<string> videographer { get; set; }
        public List<string> videolocation { get; set; }
        public List<string> related { get; set; }
        public List<string> audio { get; set; }
        public List<string> customlink { get; set; }
        public List<string> story_sport { get; set; }
        public List<string> teasertitle { get; set; }
        public List<string> teaser { get; set; }
        public List<string> grade { get; set; }
        public List<string> showratings { get; set; }
        public List<string> date { get; set; }
        public List<string> ourscore { get; set; }
        public List<string> theirscore { get; set; }
        public List<string> opponent { get; set; }
        public List<string> sport { get; set; }
    }

    public class Full
    {
        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 Medium
    {
        public string url { get; set; }
        public int width { get; set; }
        public int height { get; set; }
    }

    public class Large
    {
        public string url { get; set; }
        public int width { get; set; }
        public int height { get; set; }
    }

    public class Carouselthumb
    {
        public string url { get; set; }
        public int width { get; set; }
        public int height { get; set; }
    }

    public class Tsmediumblock
    {
        public string url { get; set; }
        public int width { get; set; }
        public int height { get; set; }
    }

    public class Tsbigblock
    {
        public string url { get; set; }
        public int width { get; set; }
        public int height { get; set; }
    }

    public class Small
    {
        public string url { get; set; }
        public int width { get; set; }
        public int height { get; set; }
    }

    public class ThumbnailImages
    {
        public Full full { get; set; }
        public Thumbnail thumbnail { get; set; }
        public Medium medium { get; set; }
        public Large large { get; set; }
        public Carouselthumb carouselthumb { get; set; }
        public Tsmediumblock tsmediumblock { get; set; }
        public Tsbigblock tsbigblock { get; set; }
        public Small small { get; set; }
    }

    public class Post
    {
        public int id { get; set; }
        public string type { get; set; }
        public string slug { get; set; }
        public string url { get; set; }
        public string status { get; set; }
        public string title { get; set; }
        public string title_plain { get; set; }
        public string content { get; set; }
        public string excerpt { get; set; }
        public string date { get; set; }
        public string modified { get; set; }
        public List<object> categories { get; set; }
        public List<object> tags { get; set; }
        public Author author { get; set; }
        public List<object> comments { get; set; }
        public List<object> attachments { get; set; }
        public int comment_count { get; set; }
        public string comment_status { get; set; }
        public CustomFields custom_fields { get; set; }
        public string thumbnail { get; set; }
        public string thumbnail_size { get; set; }
        public ThumbnailImages thumbnail_images { get; set; }
    }

    public class Query
    {
        public bool ignore_sticky_posts { get; set; }
    }

    public class RootObject
    {
        public string status { get; set; }
        public int count { get; set; }
        public int count_total { get; set; }
        public int pages { get; set; }
        public List<Post> posts { get; set; }
        public Query query { get; set; }
    }
}
公共类提要
{
公共类作者
{
公共int id{get;set;}
公共字符串slug{get;set;}
公共字符串名称{get;set;}
公共字符串first_name{get;set;}
公共字符串last_name{get;set;}
公共字符串昵称{get;set;}
公共字符串url{get;set;}
公共字符串说明{get;set;}
}       
公共类自定义字段
{
公共列表sno_标题{get;set;}
公共列表sno_deck{get;set;}
公共列表sno_格式{get;set;}
公共列表sno_longform_顺序{get;set;}
公共列表sno_longform_title{get;set;}
公共列表sno_sr_标记{get;set;}
公共列表sno_sr_cat{get;set;}
公共列表sno_sr_title{get;set;}
公共列表sno_longform_main_title{get;set;}
公共列表sno\u rails\u编号{get;set;}
公共列表sno_rails_writer{get;set;}
公共列表sno_rails_type{get;set;}
公共列表sno_rails_stories{get;set;}
公共列表sno_longform_图像{get;set;}
公共列表sno_longform_image_master{get;set;}
公共列表sno_摘要{get;set;}
公共列表编写器{get;set;}
公开列表作业标题{get;set;}
公共列表功能图像{get;set;}
公共列表视频{get;set;}
公共列表摄像器{get;set;}
公共列表视频位置{get;set;}
与公共列表相关的{get;set;}
公共列表音频{get;set;}
公共列表自定义链接{get;set;}
公共列表故事{get;set;}
公共列表标题{get;set;}
公共列表摘要程序{get;set;}
公共列表等级{get;set;}
公共列表显示分级{get;set;}
公共列表日期{get;set;}
公共列表ourscore{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;}
}
公共类大型
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公共类旋转木马
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公共类Tsmediumblock
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公共类Tsbigblock
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公共小班
{
公共字符串url{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
公共类缩略图图像
{
公共完整{get;set;}
公共缩略图{get;set;}
公共媒体媒体{get;set;}
公共大型{get;set;}
公共旋转木马旋转木马{get;set;}
公共Tsmediumblock Tsmediumblock{get;set;}
公共Tsbigblock Tsbigblock{get;set;}
公共小型{get;set;}
}
公营职位
{
公共int id{get;set;}
公共字符串类型{get;set;}
公共字符串slug{get;set;}
公共字符串url{get;set;}
公共字符串状态{get;set;}
公共字符串标题{get;set;}
公共字符串标题\u plain{get;set;}
公共字符串内容{get;set;}
公共字符串摘录{get;set;}
公共字符串日期{get;set;}
公共字符串已修改{get;set;}
公共列表类别{get;set;}
公共列表标记{get;set;}
公共作者{get;set;}
公共列表注释{get;set;}
公共列表附件{get;set;}
public int comment_count{get;set;}
公共字符串注释_状态{get;set;}
公共自定义字段自定义_字段{get;set;}
公共字符串缩略图{get;set;}
公共字符串缩略图大小{get;set;}
公共缩略图图像缩略图图像{get;set;}
}
公共类查询
{
公共bool ignore_sticky_posts{get;set;}
}
公共类根对象
{
公共字符串状态{get;set;}
公共整数计数{get;set;}
公共整数计数\u总计{get;set;}
公共整型页{get;set;}
公共列表发布{get;set;}
公共查询查询{get;set;}
}
}

您可以使用Newtonsoft Json将类转换为Json字符串,并传递该字符串,然后在新活动中对其进行反序列化

确保引用Newtonsoft JSON

var MySerializedObject = JsonConvert.SerializeObject(MyComplexObject);
MyIntent.PutExtra("MyComplexObject", MySerializedObject);
然后,为了让它回到物体上

var MyJsonString = Intent.GetStringExtra("MyComplexObject");
var MyObject = JsonConvert.DeserializeObject<ObjectType>(MyJsonString);
var MyJsonString=Intent.GetStringExtra(“MyComplexObject”);
var MyObject=JsonConvert.DeserializeObject(MyJsonString);
只要确保MyJsonString完全符合您的期望,并且在反序列化之前不为null,否则它可能引发异常