как десериализовать объект в viewmodel в форме xamarin - PullRequest
0 голосов
/ 18 октября 2019

мне нужно десериализовать объект, так как я попробовал некоторые способы, которые прокомментированы, но не работают

   public async Task FetchData()
    {
        using (HttpClient hc = new HttpClient())
        {
            MessageList msgList = null;
            try
            {
                IsBusy = true;
                var jsonString = await hc.GetStringAsync(url);
                //string json = await jsonString.Content.ReadAsStringAsync();
                //msgList = JsonConvert.DeserializeObject<MessageList>(jsonString);
                //foreach (var user in msgList) { 
                    //string IsRead = obj.hasBeenRead;
                    //if(IsRead== "true")
                    //{
                    //    obj.IsRedDotVisible = false;
                    //}
                    //else
                    //{
                    //    obj.IsRedDotVisible = true;
                    //}

                    //OpenData.Add(user);
                    OpenData = MessageList.FromJson(jsonString);

               // }
                // IsEmpty = OpenData.Count == 0;
            }

 and i have Message list is like this 

public partial class MessageList
{ 
    [JsonProperty("threadId")]
    public int threadId { get; set; }
    [JsonProperty("dealId")]
    public int dealId { get; set; }
    [JsonProperty("topic")]
    public string topic { get; set; }
    [JsonProperty("lastPostDate")]
    public Nullable<DateTime> lastPostDate { get; set; }
    [JsonProperty("lastPostBy")]
    public string lastPostBy { get; set; }
    [JsonProperty("hasBeenRead")]
    public string hasBeenRead { get; set; }
    [JsonProperty("lastMessage")]
    public string lastMessage { get; set; }
    [JsonProperty("partyName")]
    public string partyName { get; set; }
    public bool IsRedDotVisible { get; set; }
}
public partial class MessageList
{
    public static ObservableCollection<MessageList> FromJson(string json) => JsonConvert.DeserializeObject<ObservableCollection<MessageList>>(json);
}
}

, и я могу отображать данные в списке, но я хочу десериализовать объект по мере необходимости добавитькакое-то условие там, так как это сделать, может кто-нибудь помочь мне с этим.

...