我试图在Windows Phone 7项目中使用RestSharp(http://restsharp.org/),但我遇到了一个问题,它似乎与RestSharp使用的Newtonsoft Json.NET库有关。当我试图执行像这样我的代码:在Windows Phone 7中使用RestSharp
_restClient.ExecuteAsync<Model.Song>(restRequest, (response) =>
{
if (response.StatusCode == HttpStatusCode.OK) { }
else { }
});
,我发现了以下错误:
Could not load type 'Newtonsoft.Json.Linq.JArray' from assembly 'Newtonsoft.Json.Compact, Version=3.5.0.0, Culture=neutral, PublicKeyToken=30AD4FE6B2A6AEED'.
Newtonsoft.Json.Compact.dll
被复制到我的Windows Phone 7应用程序的Bin文件夹,所以我假设它被部署到设备上,但不知何故它不会加载它。有没有人遇到/解决过类似的问题?谢谢。
按照要求,JSON的例子:[{"type":"Song","id":60097,"title":"A Place Where You Belong","artist":{"type":"Artist","id":17,"nameWithoutThePrefix":"Bullet For My Valentine","useThePrefix":false}}]
及其类别:
[DataContract]
public class Song
{
[DataMember(Name = "id")]
public int Id { get; set; }
[DataMember(Name = "title")]
public string Title { get; set; }
[DataMember(Name = "artist")]
public Artist Artist { get; set; }
}
[DataContract]
public class Artist
{
[DataMember(Name = "id")]
public int Id { get; set; }
[DataMember(Name = "nameWithoutThePrefix")]
public string Name { get; set; }
[DataMember(Name = "useThePrefix")]
public bool UsePrefix { get; set; }
}
你不是第一个拿到这个问题。你可以发布你试图使用的JSON和C#类吗? – 2010-08-21 18:58:42
添加到原始文章,希望这是可以解决的问题,因为'DataContractJsonSerializer'对我来说真的不是很好。 – RajenK 2010-08-22 06:34:04