I need to retrieve the value in the timeestimate and timeoriginalestimate fields. It looks like the field itself is a JsonlElement.ValueKind = Number
My code is as follows:
string issueTime = !string.IsNullOrEmpty((string) singleIssue.fields.timeoriginalestimate)? (string)singleIssue.fields.timeoriginalestimate.ToString():"NULL";
[Note: I know I am casting the result to a string, this is only for testing to see if it would work]
When there is no value (i.e. null) the code passes, but as soon as there is a value in the ValueKind it throws an error.
Can anyone help me to pull the value out of the field?
Community moderators have prevented the ability to post new answers.
So, I finally figured it out after searching online. Here is what I did:
This is the windows forms code (C#):
[singleIssue is the list of issues returned from Jira]
-----------------------------------------------------------------------------------------------
if (singleIssue.fields.timeestimate != null)
{
timeEstimate =
GetValueKindNumber((System.Text.Json.JsonElement)singleIssue.fields.timeestimate);
}
Here is the private method used to deal with all related fields with VauleKind values:
---------------------------------------------------------------------------------------------
private int GetValueKindNumber(JsonElement jsonElement)
{
int valueKindResult = 0;
if (jsonElement.ValueKind == JsonValueKind.Number)
{
valueKindResult = (int)jsonElement.GetSingle();
}
return valueKindResult;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.