-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
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
Json object from string from a TCP socket #1504
Comments
What do you get if you print out For performance reasons you should consider using cbor (with cbor2 in python) for data-sending. In my use-case I reduced the cpu-load by 15% when switching to cbor instead of json-strings. Also, there is a json-parse (as well as for cbor) function which accepts a |
Hi @pboettch, Marco |
This means that the string you are sending from python has been double-dumped as json. If you print |
|
yes, I dumped twice, apparently the zmq Thanks a lot again |
Just check the possible |
awesome, I close the issue since you solved it. have a nice day. |
Hello everyone,
I am trying to pass some information from a Python script to a C++ program. The communication occurs with zmq via TCP. The Python publisher publishes the following info:
where the function
send_str_and_json()
looks like:On the C++ program, I am able to receive the dumped json string, but as soon as I try to access the keys:values after parsing, an error rises:
terminate called after throwing an instance of 'nlohmann::detail::type_error' what(): [json.exception.type_error.305] cannot use operator[] with a string argument with string Aborted (core dumped)
.As far as I can tell, the string is not parsed to create an object, but it remains a string. (confirmed by
nlohmann::json::is_object()
that returns0
. The string is correctly received by the software, and i can print it ("{\"x_NED\": \"0.0\", \"y_NED\": \"1.0\", \"z_NED\": \"2.0\", \"pose_w\": \"3.0\", \"pose_x\": \"4.0\", \"pose_y\": \"5.0\", \"pose_z\": \"6.0\"}"
)The code of the subscriber program in C++ is the following:
Do you have any clue on how to create a json object from the string passed through TCP and then access its keys:values?
Thanks a lot for your help,
Marco
PS:
The text was updated successfully, but these errors were encountered: