Json Deserialization gets error on xamarin.forms Json Deserialization gets error on xamarin.forms json json

Json Deserialization gets error on xamarin.forms


The way you are trying to extract the substring is resulting in malformed JSON

It looks like the entry is dynamic based the currently shown code.

Refactor the object model to better match the expected JSON.

public partial class RootObject<T> {    [JsonProperty("Message")]    public Message[] Message { get; set; }    [JsonProperty("Entry")]    public T[] Entry { get; set; }}public partial class Message {    [JsonProperty("Mesaage")]    public string Mesaage { get; set; }}

That way simply deserialize the response based on the expected type

//...var jsonObtained = Regex.Unescape(stringObtained);T resultObject;//Generic type objecttry{    resultObject = JsonConvert.DeserializeObject<RootObject<T>>(jsonObtained);    removeLoadingAnimation();    return resultObject;}

Where it is assumed in this case that T is of the desired type that matches the Entry key in the JSON

Otherwise you should create a model that matches the expected JSON

public partial class RootObject{    [JsonProperty("Message")]    public Message[] Message { get; set; }    [JsonProperty("Entry")]    public Entry[] Entry { get; set; }}public partial class Message {    [JsonProperty("Mesaage")]    public string Mesaage { get; set; }}public partial class Entry {    [JsonProperty("User_Id")]    public long UserId { get; set; }    [JsonProperty("Name")]    public string Name { get; set; }    [JsonProperty("Client_Id")]    public long ClientId { get; set; }    [JsonProperty("Role")]    public long Role { get; set; }    [JsonProperty("LoginName")]    public string LoginName { get; set; }    [JsonProperty("Email")]    public string Email { get; set; }    [JsonProperty("IsInternalUser")]    public string IsInternalUser { get; set; }}

and use that

//...var jsonObtained = Regex.Unescape(stringObtained);RootObject resultObject;try{    resultObject = JsonConvert.DeserializeObject<RootObject>(jsonObtained);    removeLoadingAnimation();    return resultObject;}