OkOk
JsonSerializer.Deserialize will not translate number to string
I am trying to deserialize JSON into an object and one of the JSON values is a is sometimes a string and sometimes a number which will not translate into a string property of an object.
Previous forum questions recommend using the attribute JsonNumberHandling to translate possible numbers into strings but it doesn't seem to work in my simple example.
My usage:
My error: System.InvalidOperationException: ''JsonNumberHandlingAttribute' is only valid on a number or a collection of numbers when applied to a property or field. See member 'position' on type 'Confluence.Domain.Info.Generator.Extensions'.'
My error: System.InvalidOperationException: ''JsonNumberHandlingAttribute' is only valid on a number or a collection of numbers when applied to a property or field. See member 'position' on type 'Confluence.Domain.Info.Generator.Extensions'.'
20 replies
✅ "Paste JSON as classes" functionality in VS
If your JSON has two keys of the same name with different values inside, should you let VS create multiple classes called "exampleClass" and "exampleClass1" or should you create one single class that contains all of these properties?
Example JSON: "{
"results": [
{
"id": "73827820",
"_links": {
"webui": "/pages/viewpage.action?pageId=73827820",
"edit": "/pages/resumedraft.action?draftId=73827820&draftShareId=f7777609-f3b9-4875-8904-e3b99c6870b4",
"tinyui": "/x/7IVmB",
"self": "https://confluence.vll.se/rest/api/content/73827820"
},
}
],
"start": 0,
"limit": 25,
"size": 1,
"_links": {
"self": "https://confluence.vll.se/rest/api/content?spaceKey=~LONO05&title=Tj%C3%A4nstedom%C3%A4ner2",
"base": "https://confluence.vll.se",
"context": ""
}
}"
Pasting this will make VS generate the classes
public class _Links
{
public string self { get; set; }
public string _base { get; set; }
public string context { get; set; }
}
and
public class _Links1
{
public string webui { get; set; }
public string edit { get; set; }
public string tinyui { get; set; }
public string self { get; set; }
}
Should I instead create only the class "_Links" and have it contain all of the combined properties like so?
public class _Links
{
public string self { get; set; }
public string _base { get; set; }
public string context { get; set; }
public string webui { get; set; }
public string edit { get; set; }
public string tinyui { get; set; }
public string self { get; set; }
}
5 replies
❔ Visual Studio - How to write out all properties when instansiating a class?
I would like to write out all properties automatically when creating an object
Seems like something VS would have a solution for?
(Could not find my answer on stackoverflow/chatgpt)
24 replies
❔ Smart Regex
Is there some general Regex that websites apply to find the most matching alternative from a list of words?
Example: A customer searches for "DogService.v1.Google"
Now the regex needs to be able to determine if that is closer to one of these two alternatives:
"CatService.V1"
"DogSvc.Google"
9 replies
❔ ✅ Search for specific value that is contained inside some variable while debugging VS
When debugging a large project, I know that one of my many variables will contain a string valled "ValueX".
I need to find what the name of the variable that contains the value "ValueX".
There are so many objects and nestings that I need to "Search" for the value, it is not good enough to manually look at every local variable.
3 replies
❔ Enabling "Always Encrypted" created a clash of datatypes
My normal working code crashes when enabling encryption and saving.
Operand type clash: nvarchar is incompatible with nvarchar(4000) encrypted..
I tried changing forcing the nvarchar to 4000 and I enabled everything I saw in the docs.
28 replies