When I'm converting Json objects to c#, I got an issue In which my Json has fields with $ symbol(ex: $t).But c# doesn't accept fields with special characters. If i try to replace $ with any other letters in my c# code, I'm unable to get data from 3rd party because of the change in naming.
How can I solve this issue?
Json string:
"author": [(1)
{
"name": {
"$t": "theabctv"
},-
"uri": {
$t": "http://gdata.abc.com/feeds/api/users/theabctv"
},-
"yt$userId": {
"$t": "tCUABCCT7wYG1PMCpw"
}-
}-
],-
C# code:-
public class Author2
{
public Name2 name { get; set; }
public Uri2 uri { get; set; }
public YtUserId __invalid_name__yt$userId { get; set; }
}
public class Name2
{
public string __invalid_name__$t { get; set; }
}
public class Uri2
{
public string __invalid_name__$t { get; set; }
}
public class YtUserId
{
public string __invalid_name__$t { get; set; }
}
There is no way to declare property names with symbols in NET framework, meaning that you cant have isomorphism between the JSON objects and the C# objects without parsing the JSON data. You could replace all $ symbol with any given string (carefully chosen), manage the data in the code behind and when you need to send JSON data of the object apply the inverse replacement.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With