Skip to content

not enough examples #592

Closed
Closed

Description

@kenkit

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 ?

Activity

  1. nlohmann commented on May 24, 2017

    @nlohmann
    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.

  2. nlohmann commented on May 24, 2017

    @nlohmann
    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());
  3. nlohmann commented on May 24, 2017

    @nlohmann
    Owner

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

  4. nlohmann commented on May 24, 2017

    @nlohmann
    Owner

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

  5. nlohmann commented on May 24, 2017

    @nlohmann
    Owner

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

    (Sorry, I used the wrong index.)

  6. JakeShirley commented on May 24, 2017

    @JakeShirley

    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.

  7. JakeShirley commented on May 24, 2017

    @JakeShirley

    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.

  8. gregmarr commented on May 24, 2017

    @gregmarr
    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.

  9. nlohmann commented on May 24, 2017

    @nlohmann
    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.

  10. gregmarr commented on May 24, 2017

    @gregmarr
    Contributor

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

  11. gregmarr commented on May 24, 2017

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

    This is not a valid JSON string.

  12. gregmarr commented on May 24, 2017

    @gregmarr
    Contributor

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

  13. gregmarr commented on May 24, 2017

    @gregmarr
    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 .

  14. nlohmann commented on May 24, 2017

    @nlohmann
    Owner

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

  15. kenkit commented on May 24, 2017

    @kenkit
    Author

    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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    solution: invalidthe issue is not related to the library

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions