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

add Json #38

Closed
mathio3 opened this issue May 10, 2021 · 1 comment
Closed

add Json #38

mathio3 opened this issue May 10, 2021 · 1 comment

Comments

@mathio3
Copy link

mathio3 commented May 10, 2021

add simple json handler if need to post Json

using namespace std;

namespace R2 {

class Json {
public:

	string serialize(map<string, string> data)
	{
		string _d;

		_d = "{";

		map<string, string>::iterator it;

		for (it = data.begin(); it != data.end(); ++it)
		{
			if (it == prev(data.end()))
			{
				_d += "\"" + it->first + "\": \"" + it->second + "\"}";
				break;
			}

			_d += "\"" + it->first + "\": \"" + it->second + "\", ";
		}

		return _d;
	}

};}

#USING :

R2::Json json; 
string data = json.serialize(map<string, string>({{"username", "mathio"},{"password", "MyPass"}}));
@elnormous
Copy link
Owner

You should use a JSON library like https://github.com/nlohmann/json for JSON encoding. JSON is not a part of the HTTP standard (RFC 7231) so it is out of the scope of this library. I added an example on hot wo send a JSON POST in b6b8795.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants