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

Trouble using parser with initial dictionary #243

Closed
calkinssean opened this issue May 11, 2016 · 3 comments
Closed

Trouble using parser with initial dictionary #243

calkinssean opened this issue May 11, 2016 · 3 comments

Comments

@calkinssean
Copy link

Hey guys, I'm trying to use this parser along with OneSignal (push notifications) and I'm having a little trouble. It doesn't help that I'm completely new to C++ but I was wondering if you could give me a little point in the right direction. The data I'm trying to parse looks like this:
{
"coinsAdded": "10",
"sound": "default",
"title": "test"
}
and it's in a const char* called additionalData.
Any help you guys could give would be awesome.
Thanks, and great work!

@calkinssean
Copy link
Author

I forgot to mention I'm using xCode 7.3.1

@nlohmann
Copy link
Owner

Hi @calkinssean,

I am not sure whether I understand you correctly. But it seems to me that this is what you want:

#include <json.hpp>

using nlohmann::json;

int main()
{
    // your data as const char*
    const char* additionalData = "{\"coinsAdded\": \"10\", \"sound\": \"default\", \"title\": \"test\"}";

    // create a JSON object
    json j = json::parse(additionalData);

    // pretty-print
    std::cout << j.dump(4) << std::endl;
}

@calkinssean
Copy link
Author

That did it, sorry for the simplicity of my question, C++ just isn't my field at all. But you guys have done some great work here and the library works beautifully.

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

No branches or pull requests

2 participants