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

Parsing string into json doesn't preserve the order correctly. #1817

Closed
Alppuccino opened this issue Oct 28, 2019 · 7 comments · Fixed by #2258
Closed

Parsing string into json doesn't preserve the order correctly. #1817

Alppuccino opened this issue Oct 28, 2019 · 7 comments · Fixed by #2258
Assignees
Labels
kind: question release item: ✨ new feature solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@Alppuccino
Copy link

  • Describe what you want to achieve.
    I want to parse a json file from the web, downloaded into a string using libcurl, back into a json object.

  • Describe what you tried.
    Image of code
    This is what I've tried - the former cout prints the string that curl downloaded, which is in the correct order of the original json on the webserver. The second cout simply posts the same json but as a json object, which has been parsed by nlohmann::json. As you can see, it is completely jumbled up. When trying to access a nested part of the json, for example ["teams"]["players"] it returns null and crashes with error 305, cannot use operator[] with a string argument. If you need any more information please don't hesitate to reply.

  • Describe which system (OS, compiler) you are using.
    VS2015 (v140) on Windows 10

  • Describe which version of the library you are using (release version, develop branch).
    release

@nlohmann
Copy link
Owner

@Alppuccino
Copy link
Author

Alppuccino commented Oct 28, 2019

Ok thanks, but does this solve how to access nested Json elements? or is that something unrelated?

@Alppuccino
Copy link
Author

for example I want to access these parts, but it returns null with error 305
image

@nlohmann
Copy link
Owner

Does j["teams"][0]["players"][0]["name"] work?

@Alppuccino
Copy link
Author

Yes, that works a charm! Thanks so much! This may seem like a silly question, but what does the [0] actually do there? Thanks again.

@nlohmann
Copy link
Owner

It accesses the first element of an array, just like for a std::vector.

@nlohmann nlohmann added release item: ✨ new feature solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Jul 11, 2020
@nlohmann nlohmann self-assigned this Jul 11, 2020
@nlohmann nlohmann added this to the Release 3.8.1 milestone Jul 11, 2020
@nlohmann nlohmann reopened this Jul 11, 2020
@nlohmann
Copy link
Owner

To be fixed with #2258.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question release item: ✨ new feature solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants