0

我有一个来自互联网的 JSON 文件:

string JSON = reader.ReadToEnd();

它工作得很好,问题在这里:

NewsList = JsonConvert.DeserializeObject<News>(JSON) as News;

这在 WP8 项目上完美运行,但 WP7 不知何故失败了。这是我的新闻课:

    class News
    {
        [JsonProperty("jsonrpc")]
        public string Jsonrpc { get; set; }
        [JsonProperty("id")]
        public string Id { get; set; }
        [JsonProperty("result")]
        public Result Result { get; set; }
    }
    public class Result
    {
        private List<Article> articles = new List<Article>();
        [JsonProperty("articles")]
        public List<Article> Articles { get { return articles; } }
    }
    public class Article
    {
        [JsonProperty("text")]
        public string Text { get; set; }
        [JsonProperty("id")]
        public int Id { get; set; }
        [JsonProperty("date")]
        public long Date { get; set; }
        [JsonProperty("title")]
        public string Title { get; set; }
        [JsonProperty("author")]
        public string Author { get; set; }
        [JsonProperty("imageURL")]
        public string ImageURL { get; set; }
    }

这是错误:

尝试访问该方法失败:WP7RTURelease2.HomePage+News..ctor()

System.MethodAccessException 未处理 Message=尝试访问方法失败:WP7RTURelease2.HomePage+News..ctor() StackTrace:在 System.Reflection.RuntimeConstructorInfo.InternalInvoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo文化,StackCrawlMark& stackMark) 在 System.Reflection.ConstructorInfo.Invoke(Object[] parameters) 在 Newtonsoft.Json.Utilities.LateBoundReflectionDelegateFactory.<>c_ DisplayClass6`1.b_5() 在 Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateNewObject(JsonReader reader, JsonObjectContract objectContract, JsonProperty containerMember, JsonProperty containerProperty, String id, Boolean& createdFromNonDefaultConstructor) at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) 在 Newtonsoft.Json .Serialization.JsonSerializerInternalReader。在 Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) at Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) 在 Newtonsoft.Json.JsonConvert.DeserializeObject(字符串值,类型类型,JsonSerializerSettings 设置)在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](字符串值,JsonSerializerSettings 设置)在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](字符串值)在 WP7RTURelease2.HomePage.HandleResponseNews(IAsyncResult结果)在 System.Net.Browser.ClientHttpWebRequest.<>c_在 Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) 在 Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) 在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) 处键入 objectType) ,JsonSerializerSettings 设置)在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](字符串值)在 WP7RTURelease2.HomePage.HandleResponseNews(IAsyncResult 结果)在 System.Net.Browser.ClientHttpWebRequest.<>c_在 Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) 在 Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings) 在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value) 处键入 objectType) ,JsonSerializerSettings 设置)在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](字符串值)在 WP7RTURelease2.HomePage.HandleResponseNews(IAsyncResult 结果)在 System.Net.Browser.ClientHttpWebRequest.<>c_JsonSerializerSettings 设置)在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](字符串值)在 WP7RTURelease2.HomePage.HandleResponseNews(IAsyncResult 结果)在 System.Net.Browser.ClientHttpWebRequest.<>c_JsonSerializerSettings 设置)在 Newtonsoft.Json.JsonConvert.DeserializeObject[T](字符串值)在 WP7RTURelease2.HomePage.HandleResponseNews(IAsyncResult 结果)在 System.Net.Browser.ClientHttpWebRequest.<>c_DisplayClassa.b _8(Object state2) at System.Threading.ThreadPool.WorkItem.WaitCallback_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadPool.WorkItem.doWork (对象 o)在 System.Threading.Timer.ring()

4

1 回答 1

1

尝试News公开您的课程。

于 2013-08-13T14:08:59.720 回答