Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I'm making a steam trading bot, and I want to be able to fetch my inventory and send it to the other user, this is what I've done (using 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);
I get the following error:
[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
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
So my question is: How do you convert JArray to String?
If just do Response.rgInventory in System.Console.WriteLine, it's fine. But when I try to send someone a message, it's not fine because the SendChatMessage Function accepts a string as an input.
Depending on the implementation, you should be able to use:
Inv = Response.rgInventory.toString();
If this does not lead to a satisfying result, you might have to construct the string yourself. You can always go ahead and override the toString() method as well to make it fit your demands.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.