Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have the following code in c# .. can you plz help me to frame the bellow JSON string

C#
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 have to frame the following JSON srting

JavaScript
{"A":{val1:["one","two"],val2:null,val3:null},"B":null,"C":{val7:["one"],val8:null,val9:["three","four"]}




And finally i need the following JSON string .. with out null parameter and also with out null class

JavaScript
{"A":{val1:["one","two"]},"C":{val7:["one"],val9:["three","four"]} 
Posted

1 solution

If you are using newtonsoft Json:

string ignored = JsonConvert.SerializeObject(movie,
Formatting.Indented,
new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });


More here[^]
 
Share this answer
 
Comments
prabulingam,india 13-Jun-13 1:02am    
but i have to remove this too "b:{}" an empty class

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900