首页 文章

赢得Phone 8 Json序列化

提问于
浏览
0

我想使用Json.Net序列化一个对象,但我有这个例外:

'TaskHost.exe'(Gestito):carscato'System.Runtime.Serialization.dll'Eccezione first-chance di tipo'System.MethodAccessException'in mscorlib.dll eccezione first-chance di tipo'System.MethodAccessException'in mscorlib.dll在Newtonsoft.Json.dll中的Eccezione第一次机会di tipo'Newtonsoft.Json.JsonSerializationException'在Newtonsoft.Json.dll中的Eccezione第一次机会di tipo'Newtonsoft.Json.JsonSerializationException'错误从'HelloWorld.MainPage上的'username'获取值TESTLOGIN' . 在Newtonsoft.Json的Newtonsoft.Json.Serialization.ReflectionValueProvider.GetValue(对象目标),Newtonsoft.Json的Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer,Object value,JsonContainerContract contract,JsonProperty成员,JsonProperty属性,JsonContract&memberContract,Object&memberValue) .Serialization.JerialSerializerInternalWriter.SerializeObject(JsonWriter writer,Object value,JsonObjectContract contract,JsonProperty成员,JsonContainerContract collectionContract,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; }
    }
}

这个错误是什么?我按照互联网上的例子,我得到这个错误 . 为什么?

1 回答

  • 0

    修复对类的访问并写入:

    public class Login
    

    那应该可以解决你的问题 . 以防万一,编辑帖子并添加完整的json文本 .

相关问题