【发布时间】:2013-03-06 02:34:37
【问题描述】:
我正在使用 RestSharp 来使用一个安静的网络服务。我正在使用内置的 Json Deserializer 来反序列化响应。 这是回应。
[{"id":"1","latitude":"18.0155848","longitude":"-77.4988293","rating":"1","streetid":"1","username":"joel","verified":"1"},{"id":"2","latitude":"18.0155892","longitude":"-77.498774","rating":"1","streetid":"2","username":"joel","verified":"0"},{"id":"3","latitude":"18.0227736","longitude":"-77.4980039","rating":"1","streetid":"3","username":"joel","verified":"0"}]
这些是它被映射到的模型。
List<Pothole> list = new List<Pothole>();
public class Pothole
{
//getters and setters for the attributes of Pothole Model
public long Id { get; set;}
public double Latitude { get; set; }
public double Longitude { get; set; }
public double Rating{ get;set;}
public long StreetId { get; set; }
public string Username { get; set; }
public bool Verified { get; set; }
}
但是,当我进行调用时,数据没有被反序列化。我想知道对类映射的 json 响应是否有问题。由于返回的坑洞对象数组,我将响应映射到坑洞列表。我检查了 HTTP 状态代码和响应的内容,以便返回数据,它只是反序列化导致了问题。
【问题讨论】:
-
我猜您对 JSON 和您要映射到的类之间的大小写差异有疑问...
-
@SteveWellens 更新
-
@PaulSasik 是的,这就是我遇到的问题。
-
模型/类是否准确?
-
你需要匹配JSON变量的大小写。 id 而不是 Id 等。
标签: c# json windows-phone-7 deserialization restsharp