带有null成员和null类对象的JSON字符串 [英] JSON string with out null member and null class object
本文介绍了带有null成员和null类对象的JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨我在c#中有以下代码..你能不能帮我勾勒出波纹管JSON字符串
Hi i have the following code in c# .. can you plz help me to frame the bellow JSON string
class A
{
B b;
C c;
D d;
public class B
{
string val1;
string val2;
string val3;
}
public class C
{
string val4;
string val5;
string val6;
}
public class D
{
string val7;
string val8;
string val9;
}
}
i必须构建以下JSON srting
i have to frame the following JSON srting
{"A":{val1:["one","two"],val2:null,val3:null},"B":null,"C":{val7:["one"],val8:null,val9:["three","four"]}
最后我需要以下JSON字符串..使用out null参数和out null类
And finally i need the following JSON string .. with out null parameter and also with out null class
{"A":{val1:["one","two"]},"C":{val7:["one"],val9:["three","four"]}
推荐答案
如果你正在使用newtonsoft Json:
If you are using newtonsoft Json:
string ignored = JsonConvert.SerializeObject(movie,
Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
这篇关于带有null成员和null类对象的JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文