I have a Json input with both token and value in string format
{
"TOKEN1": "1000",
"TOKEN2": "2000"
}
and in Template, i have to check if TOKEN1
exist, then display that in certain format, else if TOKEN2
exist and has value then display it with certain format, so i have the logic to check if it’s null or empty and convert it to double.
<<var [SI1 = (!string.IsNullOrEmpty(TOKEN1) && decimal.Parse(TOKEN1) != 0) ? decimal.Parse(TOKEN1) : (!string.IsNullOrEmpty(TOKEN2) && decimal.Parse(TOKEN2) != 0) ? decimal.Parse(TOKEN2) : 0]>>
and finally display it with the format
<<if [SI1 == 0]>>N.A<<else>><<[SI1]:"#,##0">><</if>>
This works fine when the Value of Token is 1000
, but throws below exception when the value is 1000.01
Error! Can not resolve method ‘IsNullOrEmpty’ on type ‘System.String’.
Seems like value 1000.01 is getting converted to date.
I’m already using Json Value Parse Mode as Strict
JsonDataLoadOptions options = new JsonDataLoadOptions();
options.SimpleValueParseMode = JsonSimpleValueParseMode.Strict;
Is there any way to handle it? I cannot afford to change the Json string to double or other datatype
Currently, I’m using 22.6 version of Aspose.
@PramodMn
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): WORDSNET-28184
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
@PramodMn
Here is a relevant quote from Accessing JSON Data:
Note – Parsing of date-time values does not depend on whether the loose or strict mode is used.
LINQ Reporting Engine relies on built-in .NET routines to try parsing date-time values and cannot control these routines. In some cases, the routines may behave unexpectedly. To handle such cases the engine provides JsonDataLoadOptions.ExactDateTimeParseFormats.
A few more quotes from Accessing JSON Data:
in some scenarios, you may need to restrict strings to be recognized as date-time values. You can achieve this by specifying one or several exact formats in the context of the current culture to be used while parsing date-time values from strings as shown in the following example.
List<String> formats = new List<String>();
formats.Add("MM/dd/yyyy");
JsonDataLoadOptions options = new JsonDataLoadOptions();
options.ExactDateTimeParseFormats = formats;
JsonDataSource dataSource = new JsonDataSource(..., options);
In some scenarios, you may need to disable recognition of date-time values at all, for example, when you deal with strings containing already formatted date-time values, which you do not want to re-format using the engine. You can achieve this by setting the exact date-time parse formats to an empty list
The issues you have found earlier (filed as WORDSNET-28184) have been fixed in this Aspose.Words for .NET 25.5 update also available on NuGet.