反序列化异常:
“Newtonsoft.Json.JsonSerializationException”类型的未经处理的异常在 Newtonsoft.Json.dll 中发生
其他信息: Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[FolkPokerModes.Role]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'player', line 1, position 10.
序列化代码:
JsonSerializer js = new JsonSerializer();
string str = JsonConvert.SerializeObject(o);
byte[] buf = Encoding.UTF8.GetBytes(str);
//发送数据
//byte[] buf = System.Text.Encoding.Default.GetBytes ( a );
client.Send(buf);
传递的对象:
public class Role
{
public Role(Player player)
{
this.player = player;
}
public Role() { }
public Player player;//玩家信息(玩家与角色绑定)
public Player Player
{
get { return player; }
set { player = value; }
}
public int Location;//角色在界面的哪个位置
public int location
{
get { return Location; }
set { Location = value; }
}
public bool Landlord = false;//角色类型,是否为地主(false为农民,true为地主)
public bool landlord
{
get { return Landlord; }
set { Landlord = value; }
}
public ArrayList Remain_Subscript = new ArrayList();//保存每个角色剩余牌的图形的下标
public ArrayList Remain_Subscript1
{
get { return Remain_Subscript; }
set { Remain_Subscript = value; }
}
public ArrayList Remain_Poker = new ArrayList();//剩余的牌
public ArrayList remain_poker
{
get { return Remain_Poker; }
set { Remain_Poker = value; }
}
public ArrayList Hand_Poker = new ArrayList();//保存上手牌
public ArrayList hand_poker
{
get { return Hand_Poker; }
set { Hand_Poker = value; }
}
public ArrayList Already_Poker = new ArrayList();//已出的所有牌
public ArrayList already_poker
{
get { return Already_Poker; }
set { Already_Poker = value; }
}
怎么解决