c# - 我可以将 json 数据反序列化为静态类吗
问题描述
所以我想做的是将json数据带入一个静态类。但我目前的方法如图所示是有 2 个类,一个用于获取数据,然后另一个静态类,相同,用于保存数据
这里的目标是拥有静态数据类
internal class _iData
{
public string CompanyName { get; set; }
public string UserName { get; set; }
public string Description { get; set; }
public string Shelf { get; set; }
public string Quantiy { get; set; }
}
public static class ItemData
{
public static string CompanyName { get; set; }
public static string UserName { get; set; }
public static string Description { get; set; }
public static string Shelf { get; set; }
public static string Quantiy { get; set; }
}
_iData ob = js.Deserialize<_iData>(objText);
// Move data from instantiated class to static class
ItemData.CompanyName = ob.CompanyName;
ItemData.Description = ob.Description;
ItemData.Quantiy = ob.Quantiy;
ItemData.Shelf = ob.Shelf;
ItemData.UserName = ob.UserName;
然后我复制了不是世界末日的数据,但我觉得我错过了一些东西
解决方案
您不能反序列化为static
.
反序列化时,您将获得一个instance。static
类不能有实例(因为它们是static
)
推荐阅读
- github - 安装后无法在 Google Colab 中导入模块
- mysql - 表达式不在 GROUP BY 子句中
- javascript - 如何调试嵌入在视图中的javascript
- assembly - 在 RISC-V 程序集中的 .data 段中的地址处写入一个字节
- javascript - 如何通过 JS 代码禁用 Hellobar?
- django - 如何过滤反向外键字段上的 Django 注释
- nsis - 在 nsis 中使用 inetc 插件读取波斯文本文件
- python - Python NetworkX:基于索引的边
- ionic-framework - Ionic 3 InAppBrowser 未触发事件
- flask - 当我使用烧瓶 cli 运行我的应用程序时,为什么会收到错误“未从...获得有效的 Flask 应用程序”?