C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,648 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi
I want to the empty property in my Json to not show up
Current output
{"fields":{"sum":"Test","pro":{"ke":"T"},"itp":{"id":"10"},"cust":{"id":"13"},"cust7":{}}}
Expected
{"fields":{"sum":"Test","pro":{"ke":"T"},"itp":{"id":"10"},"cust":{"id":"13"}}}
I tried things as suggested here...
My Code
public static string JiraStructureForCreate(Era eraRequest)
{
var tudhjs = new
{
fields = new
{
sum = "st",
pro = new
{
ke = "T"
},
itp = new
{
id = "35"
},
cust = new
{
id = "23"
},
cust7 = new
{
value = ""
}
}
};
JsonSerializerSettings settings = new JsonSerializerSettings();
settings.NullValueHandling = NullValueHandling.Ignore;
var myJson = JsonConvert.SerializeObject(tudhjs, settings);
Try this approach in your real circumstances:
var cust7 = new
{
value = ""
};
if( string.IsNullOrWhiteSpace( cust7.value ) ) cust7 = null;
var tudhjs = new
{
fields = new
{
sum = "st",
// . . .
cust = new
{
id = "23"
},
cust7
}
};