【发布时间】:2014-04-25 12:19:17
【问题描述】:
我正在制作一个 Steam 交易机器人,我希望能够获取我的库存并将其发送给其他用户,这就是我所做的(使用 SteamKit2):
dynamic Response;
string Inv;
string name = Bot.SteamFriends.GetFriendPersonaName(OtherSID);
System.Console.WriteLine(name + " Said: " + message);
Response = Inventory.GetInventory(Bot.SteamClient.SteamID);
System.Console.WriteLine(Inv = Response.rgInventory);
Bot.SteamFriends.SendChatMessage(OtherSID, EChatEntryType.ChatMsg, Inv);
我收到以下错误:
[TF2 Bot 2014-04-25 20:13:18] ERROR: Microsoft.CSharp.RuntimeBinder.RuntimeBinde
rException: Cannot implicitly convert type 'Newtonsoft.Json.Linq.JArray' to 'str
ing'. An explicit conversion exists (are you missing a cast?)
at CallSite.Target(Closure , CallSite , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T
0 arg0)
at SteamBot.SimpleUserHandler.OnMessage(String message, EChatEntryType type)
in C:\Users\Raka Gunarto\Documents\GitHub\SteamBot\SteamBot\UserHandler.cs:line
47
at SteamBot.Bot.<HandleSteamMessage>b__8(FriendMsgCallback callback) in C:\Us
ers\Raka Gunarto\Documents\GitHub\SteamBot\SteamBot\Bot.cs:line 481
at SteamKit2.CallbackMsg.Handle[T](Action`1 handler)
at SteamBot.Bot.HandleSteamMessage(CallbackMsg msg) in C:\Users\Raka Gunarto\
Documents\GitHub\SteamBot\SteamBot\Bot.cs:line 471
at SteamBot.Bot.BackgroundWorkerOnDoWork(Object sender, DoWorkEventArgs doWor
kEventArgs) in C:\Users\Raka Gunarto\Documents\GitHub\SteamBot\SteamBot\Bot.cs:l
ine 731
所以我的问题是:如何将 JArray 转换为 String? 如果只是在 System.Console.WriteLine 中做 Response.rgInventory 就可以了。但是当我尝试向某人发送消息时,这并不好,因为 SendChatMessage 函数接受字符串作为输入。
【问题讨论】:
-
旧的 toString() 方法对你有用吗?