当我手动将此消息发送到 MakeAction 时,它会起作用并弹出消息框:
string json = @"{'action':'turncompleted', 'messageID':'123123123', 'playerID':'100000067174580', 'round':1, 'values':[{'longitude':21.09375, 'latitude':24.527134822598}, {'longitude':1.40625, 'latitude':23.885837699862}]}";
public void MakeAction(string message)
{
Poker_Server_v4_0.Action a = JsonConvert.DeserializeObject<Poker_Server_v4_0.Action>(message);
System.Windows.Forms.MessageBox.Show(a.action + a.messageID);
}
但是当我使用来自 PubNub 的消息时它不起作用:
static void DisplaySubscribeReturnMessage(string result)
{
//Receives the message from Pubnub takes care of the Action.
MessageToAction MTA = new MessageToAction();
MTA.MakeAction(result);
}
来自 PubNub 的消息与我手动创建的消息略有不同:
[{\"action\":\"turncompleted\",\"messageID\":\"123123123\",\"playerID\":\"100000067174580\",\"round\":1,\"answers\":[{\"longitude\":21.09375,\"latitude\":24.527134822598},{\"longitude\":1.40625,\"latitude\":23.885837699862}]},\"13926740640746402\",\"chinese-jefecito\"]
我试图删除括号和斜线文本,但“值”值周围的斜线也被替换。
我想知道我在这里做错了什么?
这里也是动作类:
class Action
{
[JsonProperty("action")]
public string action { get; set; }
[JsonProperty("messageID")]
public string messageID { get; set; }
[JsonProperty("gameID")]
public string gameID { get; set; }
[JsonProperty("invitorFacebookID")]
public string invitorFacebookID { get; set; }
[JsonProperty("gametype")]
public string gametype { get; set; }
[JsonProperty("numberOfPlayers")]
public string numberOfPlayers { get; set; }
//public List<string> longitude { get; set; }
//public List<string> latitude { get; set; }
//public List<string> values { get; set; }
[JsonProperty("players")]
public List<Players> players { get; set; }
//Should be empty and removed!
[JsonProperty("values")]
public List<Value> values { get; set; }
public Action() { }
}
class Players
{
//Players
[JsonProperty("playerID")]
public string playerID { get; set; }
[JsonProperty("facebookID")]
public string facebookID { get; set; }
}
class Value
{
//Answers
[JsonProperty("longitude")]
public string longitude {get; set;}
[JsonProperty("latitude")]
public string latitude { get; set; }
}
提前致谢, 托马斯