如何传递List
我有列表,我想将其传递给另一个活动 当我在第一个活动中使用 JsonConvert.serialize 对其进行序列化并在另一个活动中对其进行反序列化时,它仅在我将其记录到控制台时才有效,但是当我将其设置为值时,它会给出一个错误,指出该值为 null 。
//活动一 string jsonData = JsonConvert.SerializeObject(VideosList);意图意图 = new Intent(this, typeof(HomeActivity)); Intent.PutExtra("媒体", jsonData); StartActivity(intent);
//活动二 string jsonData2 = Intent.GetStringExtra("media"); // 我可以记录它 List
I have List and I want to pass it to another activity
when I Serialize it using JsonConvert.serialize in the first activity and deserialize it on the other one, It works only when I am logging it to console, but when I set it as a value it gives me an error that says the value is null.
//activity onestring jsonData = JsonConvert.SerializeObject(VideosList); Intent intent = new Intent(this, typeof(HomeActivity)); intent.PutExtra("media", jsonData); StartActivity(intent);
//activity twostring jsonData2 = Intent.GetStringExtra("media"); // i can log it List<Video> list = JsonConvert.DeserializeObject<List<Video>>(jsonData2); here give me null
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,我认为数据类型不应该声明为字符串。所以你可以尝试使用下面的代码。
并在其他活动中使用它:
如果它不起作用,您可能需要自己实现 Parcelable 接口。
At first, I think the data type shouldn't be declared as the string. So you can try to use the following code.
And use it in the other activity:
If it doesn't work, you may need to implement the Parcelable interface by your self.