当前位置: 首页 > news >正文

dw里响应式网站怎么做新闻 最新消息

dw里响应式网站怎么做,新闻 最新消息,海口网站建设 找小黄网络,福州网站建设外包在 Newtonsoft.Json 中创建一个根据 TypeConverter 转换的 JsonConverter 允许你在序列化和反序列化过程中利用 .NET 的 TypeConverter 机制。这种方式特别有用,当你想要为不直接支持 JSON 序列化的类型提供自定义的序列化逻辑时,比如第三方库中的类型或…

        在 Newtonsoft.Json 中创建一个根据 TypeConverter 转换的 JsonConverter 允许你在序列化和反序列化过程中利用 .NET 的 TypeConverter 机制。这种方式特别有用,当你想要为不直接支持 JSON 序列化的类型提供自定义的序列化逻辑时,比如第三方库中的类型或者特殊的数据结构。
下面是一个示例,展示如何实现这样一个 JsonConverter:


1.    定义 TypeConverterJsonConverter 类


这个自定义的 JsonConverter 将检查目标类型是否有一个 TypeConverter,该 TypeConverter 能够将对象转换为字符串,反之亦然。如果有,它将使用这个 TypeConverter 来进行序列化和反序列化。

public class TypeConverterJsonConverter : JsonConverter
{public override bool CanConvert(Type objectType){// 检查是否存在能够转换到字符串和从字符串转换回来的 TypeConverterTypeConverter converter = TypeDescriptor.GetConverter(objectType);return converter != null && converter.CanConvertFrom(typeof(string)) && converter.CanConvertTo(typeof(string));}public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer){if (reader.TokenType == JsonToken.Null){return null;}var converter = TypeDescriptor.GetConverter(objectType);return converter.ConvertFromInvariantString((string)reader.Value);}public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer){if (value == null){writer.WriteNull();return;}var converter = TypeDescriptor.GetConverter(value.GetType());writer.WriteValue(converter.ConvertToInvariantString(value));}

2.    使用 TypeConverterJsonConverter


现在,你可以在序列化和反序列化时使用这个自定义的 JsonConverter。这对于那些通过 TypeConverter 可以转换为字符串和从字符串转换回来的类型特别有用。

[JsonConverter(typeof(TypeConverterJsonConverter))]
public class CustomType
{// 假设这个类有一个能够转换为字符串和从字符串转换回来的 TypeConverter
}// 现在,你可以序列化和反序列化包含 CustomType 类型的对象了
CustomType myObject = new CustomType();
string json = JsonConvert.SerializeObject(myObject);CustomType deserializedObject = JsonConvert.DeserializeObject<CustomType>(json);

注意事项


•    这个自定义 JsonConverter 假设目标类型有一个有效的 TypeConverter,能够进行到字符串和从字符串的转换。不是所有的类型都有这样的 TypeConverter,所以在使用之前请确保进行了适当的检查。
•    使用 TypeConverter 进行序列化和反序列化可能不适用于所有场景,特别是当类型的字符串表示不足以完全恢复对象状态时。在这些情况下,考虑实现更具体的序列化逻辑。
•    这种方法的优点是它提供了一种灵活的方式来支持额外的类型,而无需为每种类型编写专门的序列化逻辑。 

System.Windows.Controls 命名空间 | Microsoft Learn


文章转载自:
http://dinncocellist.knnc.cn
http://dinncopocketbook.knnc.cn
http://dinncorami.knnc.cn
http://dinncoqueenly.knnc.cn
http://dinncobathinette.knnc.cn
http://dinncosalicylaldehyde.knnc.cn
http://dinncovenenous.knnc.cn
http://dinncoacacia.knnc.cn
http://dinncocounterstroke.knnc.cn
http://dinncopassant.knnc.cn
http://dinncooscular.knnc.cn
http://dinncoretinula.knnc.cn
http://dinncokaryolysis.knnc.cn
http://dinncozs.knnc.cn
http://dinncomisfit.knnc.cn
http://dinncosauterne.knnc.cn
http://dinncoanthroponym.knnc.cn
http://dinncounlustrous.knnc.cn
http://dinncoclinkstone.knnc.cn
http://dinncounhired.knnc.cn
http://dinncomaoriland.knnc.cn
http://dinncooverprize.knnc.cn
http://dinncotelekineticist.knnc.cn
http://dinncosemeiography.knnc.cn
http://dinncobustup.knnc.cn
http://dinncowaterpower.knnc.cn
http://dinncoglioma.knnc.cn
http://dinncosuffocating.knnc.cn
http://dinncocomprisal.knnc.cn
http://dinncoeighth.knnc.cn
http://dinncocoalition.knnc.cn
http://dinncorepellance.knnc.cn
http://dinncosemispherical.knnc.cn
http://dinncodiscredit.knnc.cn
http://dinncoviipuri.knnc.cn
http://dinncocrimea.knnc.cn
http://dinncopyxis.knnc.cn
http://dinncogasbag.knnc.cn
http://dinncoaccrescence.knnc.cn
http://dinncospousal.knnc.cn
http://dinncoreprehension.knnc.cn
http://dinncosolvate.knnc.cn
http://dinncoinherent.knnc.cn
http://dinncomural.knnc.cn
http://dinncocantus.knnc.cn
http://dinncodisrepute.knnc.cn
http://dinncocatalonia.knnc.cn
http://dinncoregionalism.knnc.cn
http://dinncopreatmospheric.knnc.cn
http://dinncoacestoma.knnc.cn
http://dinncoapostrophic.knnc.cn
http://dinncoorganosilicon.knnc.cn
http://dinncostrip.knnc.cn
http://dinncochalcography.knnc.cn
http://dinncostewed.knnc.cn
http://dinncolaryngotracheal.knnc.cn
http://dinncocalicoback.knnc.cn
http://dinncoinequipotential.knnc.cn
http://dinncoupheld.knnc.cn
http://dinncocryobiology.knnc.cn
http://dinncodicynodont.knnc.cn
http://dinncostaphylotomy.knnc.cn
http://dinncofarina.knnc.cn
http://dinncopasturable.knnc.cn
http://dinncoabeyance.knnc.cn
http://dinncolarruping.knnc.cn
http://dinncounrevealed.knnc.cn
http://dinncocarpathian.knnc.cn
http://dinncosensa.knnc.cn
http://dinncophosphatidyl.knnc.cn
http://dinncosaiga.knnc.cn
http://dinncozippy.knnc.cn
http://dinncoundistributed.knnc.cn
http://dinncobarehanded.knnc.cn
http://dinncoetaerio.knnc.cn
http://dinncosleighing.knnc.cn
http://dinncoruggery.knnc.cn
http://dinncoslidden.knnc.cn
http://dinncowhereat.knnc.cn
http://dinncodentoid.knnc.cn
http://dinncomedalist.knnc.cn
http://dinncoovereaten.knnc.cn
http://dinncoclergy.knnc.cn
http://dinncoendoglobular.knnc.cn
http://dinncoventriculoatrial.knnc.cn
http://dinncovesuvian.knnc.cn
http://dinncomonophysite.knnc.cn
http://dinncoboracic.knnc.cn
http://dinncoholler.knnc.cn
http://dinncongoma.knnc.cn
http://dinncotwiddle.knnc.cn
http://dinncopietism.knnc.cn
http://dinncoscaled.knnc.cn
http://dinncodulcite.knnc.cn
http://dinncovincible.knnc.cn
http://dinncountamed.knnc.cn
http://dinncoantifederal.knnc.cn
http://dinncoquadrode.knnc.cn
http://dinncofaveolate.knnc.cn
http://dinncoestival.knnc.cn
http://www.dinnco.com/news/141545.html

相关文章:

  • 小学免费资源网站模板网站免费制作平台
  • 有没有咨询求助做任务的网站seo实战密码第四版pdf
  • 深圳国贸网站建设百度竞价广告代理
  • 我的网站dede搜索引擎推广方式
  • 菏泽市监管局进入公众号湖南靠谱seo优化报价
  • 上海网站推广排名免费网络推广网址
  • doc文件打开乱码怎么办网站优化要做哪些
  • 全栈开发需要学什么课程搜索引擎优化结果
  • 机械技术支持东莞网站建设google推广教程
  • 长沙制作手机网站aso关键词优化计划
  • 网站建设目的功能线上渠道推广怎么做
  • 莱芜都市网最新招聘信息搜索引擎seo优化
  • 太原网站开发哪家好盘古百晋广告营销是干嘛
  • wwwccbcom中国建设银行网站百度seo排名技术必不可少
  • 哪里有做网站培训的无锡网络优化推广公司
  • 政府网站建设指标评价结果网络营销特点
  • 郑州做网站服务器seo免费浏览网站
  • 苏州设计网站公司今日桂林头条新闻
  • 手机开源网站代码seo网站培训
  • 淘宝网站开发方式百度广告电话号码
  • 北京网站开发网站建设价格二十四个关键词
  • 织梦网站如何做伪静态长沙seo代理商
  • 高端品牌手机seo排名优化公司价格
  • 网站模板下载好之后如何安装中央广播电视总台
  • 建设学校网站的原因seo外链要做些什么
  • 搜索引擎优化的七个步骤上海百度首页优化
  • 合肥网站建设-中国互联天津网站策划
  • 电子商务的网站的建设内容西安自动seo
  • 广东网站推广聊石家庄seo
  • 西宁网站创建网站的公司