Ras Gulla
Ras Gulla
Explore posts from servers
CC#
Created by Ras Gulla on 1/15/2025 in #help
Newtonsoft Json not deserializing with some property/constructor names
Hi, I'm using newtonsoft json to serialize and deserialize my classes. Everything works perfect until I put the name ID, Identifier, UniqueIdentifier anywhere in my class or Constructor which is to be deserialized. For example:
public class Command
{
public string UniqueID { get; set; }
public float PositionX { get; set; }
public float PositionY { get; set; }
public float PositionZ { get; set; }

public Command(string id, Vector3 position)
{
PositionX = position.x;
PositionY = position.y;
PositionZ = position.z;

UniqueID = id;
}
}
public class Command
{
public string UniqueID { get; set; }
public float PositionX { get; set; }
public float PositionY { get; set; }
public float PositionZ { get; set; }

public Command(string id, Vector3 position)
{
PositionX = position.x;
PositionY = position.y;
PositionZ = position.z;

UniqueID = id;
}
}
This serializes perfectly but when I try to deserialize it, the Identifier is null. If I change the name to something else, for example key It will work and deserialize perfectly... Anyone knows the reason for it? Here's what I receive and try to deserialize:
{
"PositionX":7.63098526,
"PositionY":15.25,
"PositionZ":12.0,
"RotationX":0.0,
"RotationY":0.0,
"RotationZ":0.0,
"RotationW":1.0,
"UniqueID":"40dd0008-bc4c-4988-a9f9-835f6a0c2ac9"
}
{
"PositionX":7.63098526,
"PositionY":15.25,
"PositionZ":12.0,
"RotationX":0.0,
"RotationY":0.0,
"RotationZ":0.0,
"RotationW":1.0,
"UniqueID":"40dd0008-bc4c-4988-a9f9-835f6a0c2ac9"
}
And here's how I'm deserializing it:
public static T Deserialize(string json)
{
try
{
if (string.IsNullOrEmpty(json))
{
Debug.LogError("Cannot deserialize null or empty JSON.");
return null;
}

return JsonConvert.DeserializeObject<T>(json);
}
catch (Exception ex)
{
Debug.LogError($"Deserialization failed: {ex.Message}");
return null;
}
}
public static T Deserialize(string json)
{
try
{
if (string.IsNullOrEmpty(json))
{
Debug.LogError("Cannot deserialize null or empty JSON.");
return null;
}

return JsonConvert.DeserializeObject<T>(json);
}
catch (Exception ex)
{
Debug.LogError($"Deserialization failed: {ex.Message}");
return null;
}
}
If anyone have any good explanation for it, please let me know.
42 replies
CDCloudflare Developers
Created by Ras Gulla on 7/19/2024 in #general-help
Transfer cloudflare domain
How can I transfer my fomain from one cloudflare account to another cloudflare account. I have many domains bought from cloudflare, each on different account. Now I want to transfer all of those domains to one single account, How can I?
7 replies