【发布时间】:2014-01-21 08:51:12
【问题描述】:
我想使用 Json.Net 序列化一个对象,但我有这个例外:
'TaskHost.exe' (Gestito): caricato 'System.Runtime.Serialization.dll' 在 mscorlib.dll 中 Eccezione 第一次出现“System.MethodAccessException” 在 mscorlib.dll 中 Eccezione 第一次出现“System.MethodAccessException” Eccezione 在 Newtonsoft.Json.dll 中的第一次机会“Newtonsoft.Json.JsonSerializationException” Eccezione 在 Newtonsoft.Json.dll 中的第一次机会“Newtonsoft.Json.JsonSerializationException” 从“HelloWorld.MainPage+TestLogin”上的“用户名”获取值时出错。 在 Newtonsoft.Json.Serialization.ReflectionValueProvider.GetValue(对象目标) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter 编写器,对象值,JsonContainerContract 合同,JsonProperty 成员,JsonProperty 属性,JsonContract& memberContract,Object& memberValue) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter 编写器,对象值,JsonObjectContract 合同,JsonProperty 成员,JsonContainerContract 集合合同,JsonProperty containerProperty) 在 Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeValue(JsonWriter writer, Object value, JsonContract valueContract
我的序列化对象方法:
Login login = new Login();
login.username = txtUsername.Text;
login.password = txtPassword.Password;
System.Diagnostics.Debug.WriteLine("Username: " + login.username);
System.Diagnostics.Debug.WriteLine("Password: " + login.password);
try
{
String json = JsonConvert.SerializeObject(login);
System.Diagnostics.Debug.WriteLine("Json per HttpRequest: " + json);
}
catch (Exception ex)
{
System.Diagnostics.Debug.WriteLine(ex.Message);
System.Diagnostics.Debug.WriteLine(ex.StackTrace);
}
还有登录类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace HelloWorld
{
class Login
{
public String username { get; set; }
public String password { get; set; }
}
}
这是什么错误?我按照互联网上的示例,我得到了这个错误。为什么?
【问题讨论】:
标签: json windows-phone-7 visual-studio-2012 serialization windows-8