为什么在地球上将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"
}
答案 0 :(得分:0)
plz复制你的json响应并转换成C#类文件到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
}