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

not enough examples #592

Closed
kenkit opened this issue May 23, 2017 · 15 comments
Closed

not enough examples #592

kenkit opened this issue May 23, 2017 · 15 comments
Labels
solution: invalid the issue is not related to the library

Comments

@kenkit
Copy link

kenkit commented May 23, 2017

This is so far the greatest c++ json library, nice work.
However we don't have enough examples, I can't figure how to extract data from this simple string, I tried using the .at() but without success, please help with a working example.
["new message",{"username":"Someone","message":"Hi"}]
also lets assume we have another like this
11 ["new message",{"username":"Someone","message":"Hi"}]
how would I parse such a string ?

@nlohmann
Copy link
Owner

Parsing is described in the README. The at function is documented here, including an example. All examples can be found here: https://github.com/nlohmann/json/tree/develop/doc/examples.

Please let me know if you need further assistance.

@nlohmann
Copy link
Owner

No, the parse function expects proper JSON. But if you know the length of the non-JSON prefix, you can try something like

std::string s = R"(11 ["new message",{"username":"Someone","message":"Hi"}])";

// provide an iterator range: skip the first three bytes
json j = json::parse(s.begin() + 3, s.end());

@nlohmann
Copy link
Owner

Please have a look at the README first. All is written there.

@nlohmann
Copy link
Owner

Please just check the README. It's all there - from parsing to value manipulation to printing.

@nlohmann
Copy link
Owner

nlohmann commented May 24, 2017

In the example above, j[1]["username"] is "Someone".

(Sorry, I used the wrong index.)

@JakeShirley
Copy link

You can voice your opinion all day long, but the point of a public repo. is so you (not the author) can go make the changes you want and if you feel so inclined you can submit a pull request to get the changes back into this repository.

@JakeShirley
Copy link

JakeShirley commented May 24, 2017

and close the issue even if you don't help him/her ?

He attempted to help you multiple times.

If he just left it open, then closed it after say 2 days what's the loss in that ?

What's the point? It is just leaving more "work" in the backlog of real issues.

@gregmarr
Copy link
Contributor

You were pointed to examples, several times. You were given ideas on how to deal with the string that is not proper JSON. At this point, if you need help, you need to show the code that's not working, and not just a snippet, but something that can be used to reproduce the problem.

Also, this issue is closed, and people are still commenting on it. I fail to see the problem.

@nlohmann
Copy link
Owner

@kenkit I closed the issue, because I got the feeling that you have little interest in learning about the library, but only in your concrete problem. This is OK. Giving your issue the title "not enough examples" is misleading, because the library has plenty of examples - just not for your concrete question. I gave you some example, and pointed you to further documentation, but you kept insisting that the documentation is improper. As this is not the case, I closed the issue.

@gregmarr
Copy link
Contributor

Also, you said "I'll unfortunately have to move to another, thanks all the same." indicating that you were done here.

@gregmarr
Copy link
Contributor

11 ["new message",{"username":"Someone","message":"Hi"}]

This is not a valid JSON string.

@gregmarr
Copy link
Contributor

Thanks for the clarification, that wasn't clear from your original request.

@gregmarr
Copy link
Contributor

Yeah, that much was obvious. What wasn't obvious was

the first string is what I have after str.erase, I posted two in the hope that maybe there was a way of parsing it and ignoring the 11 .

@nlohmann
Copy link
Owner

See #592 (comment) (note: I edited the comment - I used a wrong index before)

@kenkit
Copy link
Author

kenkit commented May 24, 2017

this is what a complete example looks like. Note the json string.
https://github.com/miloyip/rapidjson/blob/master/example/tutorial/tutorial.cpp
if only I could delete this issue, i'd feel alot better.
ISSUE SOLVED NOW

@nlohmann nlohmann added the solution: invalid the issue is not related to the library label May 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

4 participants