Facebook c# SDK将地点映射到模型
本文关键字:映射 模型 SDK Facebook | 更新日期: 2023-09-27 18:03:01
下面是一个结果示例,(facebook public example)
(/搜索? q = coffee&类型= place&中心= 37.76、-122.427,距离= 1000)
我有这个模型:
[DataContract]
public class FBPlaces
{
[DataMember(Name = "data")]
public List<Place> Data { get; set; }
[DataMember(Name = "paging")]
public Paging Paging { get; set; }
}
[DataContract]
public class Paging
{
[DataMember(Name = "next")]
public string Next { get; set; }
}
[DataContract]
public class Place
{
[DataMember(Name = "location")]
public List<Location> Locations { get; set; }
[DataMember(Name = "category")]
public string Category { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "id")]
public string ID { get; set; }
}
[DataContract]
public class Location
{
[DataMember(Name = "street")]
public string Street { get; set; }
[DataMember(Name = "city")]
public string City { get; set; }
[DataMember(Name = "state")]
public string State { get; set; }
//[DataMember(IsRequired = false, Name = "country ")]
//public string Country { get; set; }
[DataMember(Name = "zip")]
public string Zip { get; set; }
[DataMember(Name = "latitude")]
public double Latitude { get; set; }
[DataMember(Name = "longitude")]
public double Longitude { get; set; }
}
问题是映射"location"数组,我得到
系统。ArgumentException:为调用方法'Void set_Item(Int32, MyProject.Models.Location)'提供的参数数量不正确
如果我删除位置,一切都很好,我得到类别+名称+Id。(但没有位置)
如何修复?
在我的实际示例(不同的位置查询)中,"国家"并不总是显示,我如何处理这种数据?
Location不是place内的数组。
试
[DataContract]
public class Place
{
[DataMember(Name = "location")]
public Location Locations { get; set; }
[DataMember(Name = "category")]
public string Category { get; set; }
[DataMember(Name = "name")]
public string Name { get; set; }
[DataMember(Name = "id")]
public string ID { get; set; }
}