Skip to content
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

wstring parsing #1147

Closed
AistisT opened this issue Jun 26, 2018 · 2 comments
Closed

wstring parsing #1147

AistisT opened this issue Jun 26, 2018 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@AistisT
Copy link

AistisT commented Jun 26, 2018

It was mentioned before that latest in dev version supports wstring parsing when creating json.
How one would go about parsing wstring. Obvious way of

	static int SendToAgent(std::wstring & data, LPCWSTR LogType)
	{
		
		if (mqttHandlerGlobal.IsAgentOnline())
		{
			nlohmann::json messageJson =
			{
				{ "DataType", u8"Test message" },
				{ "Data", data },
			};

			auto message = messageJson.dump();
			return mqttHandlerGlobal.MqttSend(message, *mqttHandlerGlobal.GetTopic());
		}
		return 0;
	}

Doesn't work as you end up with gibberish numbers in data field which then doesn't get parsed as json at the other end.

@nlohmann
Copy link
Owner

The library can only parse from std::wstring. You try to construct from a std::wstring.

So json::parse(data) should work.

@AistisT
Copy link
Author

AistisT commented Jun 26, 2018

cheers, works wonders!

@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Jun 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants