After the project update to .NET 6 from .NET Core 3.1 the Newtonsoft package fails to deserialize object. The error that I'm getting is :
System.Private.CoreLib: Exception while executing function: ExportOrder. Newtonsoft.Json: Invalid character after parsing property name. Expected ':' but got: ,. Path '', line 1, position 39.
var message = JsonConvert.DeserializeObject<OrderRequest>(myQueueItem);
The OrderRequest class:
public class OrderRequest
{
[JsonProperty]
public string RunId
{
get;
set;
}
}
And the myQueueItem that I'm sending is:
{
"input": "{\"06-24T07-05-35Z48\",\"IsSuccess\":true,\"Message\":\"Completed Successfully\"}"
}
Is it better idea to migrate to System.Text.JSON ?
CodePudding user response:
you json is not valid, it should be
var json="{\"input\": \"06-24T07-05-35Z48\",\"IsSuccess\":true,\"Message\":\"Completed Successfully\"}";
OrderRequest orderRequest=JsonConvert.DeserializeObject<OrderRequest>(json);
string message = orderRequest.Message; //Completed Successfully
class
public class OrderRequest
{
[JsonProperty("input")]
public string Input { get; set; }
public bool IsSuccess { get; set; }
public string Message { get; set; }
}