【发布时间】:2011-05-04 12:36:26
【问题描述】:
我正在尝试在 Windows Phone 7 项目中使用 RestSharp (http://restsharp.org/),但我遇到了 RestSharp 使用的 Newtonsoft Json.NET 库的问题。当我尝试像这样执行我的代码时:
_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# 类吗?
-
添加到原帖中,希望可以解决,因为
DataContractJsonSerializer对我来说并不是那么好。