We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have a client that is trying to send the following json data :
On the client side nlohmann::json j2 = { {"command", "Target Offset"}, {"args", {"1", "0", "2"}}, };
I create a string str = j2.dump(); I send str over the network to the server
On the server side
I am able to recv the data as string, but how do I convert the string back to json?
nlohmann::json j(read_msg_.body()); this line fails
I have to and from json written
void from_json(const json & j, NetworkPacket& p) { p.command = j.value("command", "");
if (j.contains("args")) p.arguments = j.value("args", p.arguments);
}
void to_json(json & j, const NetworkPacket & p) { j = json{ {"command",p.command}, "args",p.arguments }; }
and my NetworkPacket class looks like this
struct NetworkPacket { public: string command; vector arguments; };
Please help, how do I send data from client to server over the network.
The text was updated successfully, but these errors were encountered:
You need to call json::parse to create a JSON value back from the string.
Sorry, something went wrong.
Do you need further assistance with this issue?
Thank you this worked, I remember trying this at first, maybe I did something mistake. But thanks for helping me out
No branches or pull requests
I have a client that is trying to send the following json data :
On the client side
nlohmann::json j2 =
{
{"command", "Target Offset"},
{"args", {"1", "0", "2"}},
};
I create a string str = j2.dump();
I send str over the network to the server
On the server side
I am able to recv the data as string, but how do I convert the string back to json?
nlohmann::json j(read_msg_.body()); this line fails
I have to and from json written
void from_json(const json & j, NetworkPacket& p)
{
p.command = j.value("command", "");
}
void to_json(json & j, const NetworkPacket & p)
{
j = json{ {"command",p.command},
"args",p.arguments };
}
and my NetworkPacket class looks like this
struct NetworkPacket
{
public:
string command;
vector arguments;
};
Please help, how do I send data from client to server over the network.
The text was updated successfully, but these errors were encountered: