Hi @Andrus ,
For numeric properties jqgrid passes data property values as numbers like:
"{\"groupOp\":\"AND\",\"rules\":[{\"field\":\"Baas\",\"op\":\"eq\",\"data\":\"TDESKTOP\"},{\"field\":\"Liigid\",\"op\":\"eq\",\"data\":\"\"},{\"field\":\"Layoutnumb\",\"op\":\"eq\",\"data\":0}]}"
Trying to deserialize this causes exception
Cannot get the value of a token type 'Number' as a string.
The JSON value could not be converted to System.String. Path: $.rules[2].data | LineNumber: 0 | BytePositionInLine: 150.
The new issue relates this item: {\"field\":\"Layoutnumb\",\"op\":\"eq\",\"data\":0}
.
For the data
property, it is string type, but in the JSON string, this item is Number type, so it will cause this issue.
To solve this issue, you could change the 0
to \"0\"
, the updated JSON string as below:
"{\"groupOp\":\"AND\",\"rules\":[{\"field\":\"Baas\",\"op\":\"eq\",\"data\":\"TDESKTOP\"},{\"field\":\"Liigid\",\"op\":\"eq\",\"data\":\"\"},{\"field\":\"Layoutnumb\",\"op\":\"eq\",\"data\":\"0\"}]}"
.
Besides, you could also use Regex to replace the number value to string:
var _filters = "the new json string";
string pattern = @"(?<![""\w])(\d)(?![""\w])";
var result = Regex.Replace(_filters, pattern, "\"$1\"");
The result like this:
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Best Regards,
Dillion