c# 对象转JSON当为null时不转
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;


namespace test
{
class MainClass
{
public static void Main (string[] args)
{
EngineScoreSubWord sub = new EngineScoreSubWord ();
string json = "{\"subtext\":null,\"volume\":0.0,\"begin\":0.0,\"end\":0.0}";
sub = (EngineScoreSubWord)JsonConvert.DeserializeObject(json, typeof(EngineScoreSubWord));
string str = JsonConvert.SerializeObject(sub);
Console.WriteLine (str);
}
}


class EngineScoreSubWord
{
//[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]
public string subtext { get; set; }
public float volume { get; set; }
public float begin { get; set; }
public float end { get; set; }
[JsonProperty(NullValueHandling=NullValueHandling.Ignore)]
public float? score { get; set; } //add by grq 
}
}
阅读更多
个人分类: .net
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

c# 对象转JSON当为null时不转

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭