десериализация проблемы JSON xamarin

Почему Боги Земли APFile.Idне десериализуются правильно ???

У меня есть простой классAPFile-который я пытаюсь десериализовать — по какой — то причине он не десериализуетId-и я не вижу, где его неправильно 🙁

using System;
using Newtonsoft.Json;


namespace ActionShared
{
[Serializable]
public class APFile
{
    public APFile()
    {
    }

    /// <summary>
    /// File id
    /// </summary>
    [JsonProperty("id")]
    public int Id { get; set; }

    /// <summary>
    /// The id of entity that the file is attached to.
    /// </summary>
//  [JsonProperty("type")]
    [JsonIgnore]
    public int Type { get; set; }

    /// <summary>
    /// The file name including the extension.
    /// </summary>
    [JsonProperty("filename")]
    public string Filename { get; set; }

    /// <summary>
    /// The mime type of the file.
    /// </summary>
    [JsonIgnore]
    public string Mimetype { get; set; }

    /// <summary>
    /// The size of the file in bytes.
    /// </summary>
    //[JsonProperty("size")]
    [JsonIgnore]
    public int Size { get; set; }

    /// <summary>
    /// The unique id of the file creator's profile.
    /// </summary>
    //[JsonProperty("creator_id")]
    [JsonIgnore]
    public int Creator { get; set; }

    /// <summary>
    /// The unique id of the file creator's profile.
    /// </summary>
    //[JsonProperty("creator_name")]
    [JsonIgnore]
    public string CreatorName { get; set; }

    /// <summary>
    /// The date and time when the file was uploaded.
    /// </summary>
//  [JsonProperty("created_at")]
    [JsonIgnore]
    public DateTime CreatedAt { get; set; }

    /// <summary>
    /// The date and time when the file was last updated.
    /// </summary>
//  [JsonProperty("updated_at")]
    [JsonIgnore]
    public DateTime UpdatedAt { get; set; }

    /// <summary>
    /// A link to download the file.
    /// </summary>
    //[JsonProperty("url")]
    [JsonIgnore]
    public string Url { get; set; }
}
}

public void Do()
{
    string a = "{"id":910,"filename":"image.jpg"}";
    var b = JsonConvert.DeserializeObject<APFile>(a);
    // b.Id = 0 and b.Filename = "image.jpg"
}

1 ответ

  1. plz скопируйте ваш JSON responce и конвертируйте в файл C# class в http://json2csharp.com/

    public home()
            {
                InitializeComponent();
                NavigationPage.SetHasNavigationBar(this, false);
    
                PostRequest(this, "http://propertyworld.in/app/property.php?");
            }
    
    
    
    public async static void PostRequest(home instance, string URL)
            {
                var formContent = new FormUrlEncodedContent(new[]
                 {
                    new KeyValuePair<string, string>("action", "property_list"),
                });
                var myHttpClient = new HttpClient();
                var response = await myHttpClient.PostAsync(URL, formContent);
               //json variable is over responce
                var json = await response.Content.ReadAsStringAsync();
    
    
                MyJsonConvertedclass record = JsonConvert.DeserializeObject<MyJsonConvertedclass>(json);
    
                ObservableCollection<ModelClass.infoClass> ls = new ObservableCollection<ModelClass.infoClass> { };
                foreach (var point in record.records)
                {
                    ls.Add(new ModelClass.infoClass
                    {
                        info1 = Stringclass.rs + " " + point.property.price,
                        info2 = point.property.title.ToUpper(),
                        url = record.image_url + point.property.image
                    });
                }
    
                instance.newProp.ItemsSource = ls;
    //instance.yourControllname which is declares in your xaml like 
    
            }