Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
auto j3 = json::parse(respone.c_str());
if (j3.is_boolean()) // crashing without this check
g_Player[index].bVACBanned = j3.at("VACBanned").get<bool>();
for some reason it doesn't work
–
I've not used that parser before, just read its
readme.md
. It appears that both of these methods work:
bool b1 = j3.at("players")[0].at("VACBanned");
bool b2 = j3["players"][0]["CommunityBanned"];
Your JSON has one root node players
that is an array; its first element is accessible by [0]
; from that point you can access all parsed elements.
Add error checking per your tolerance level :)
P.S. This is just a syntax demo; I assume that OP can get the size of parsed array and iterate through it to get details on each player.
Also, to answer your "for some reason it doesn't work":
g_Player[index].bVACBanned = j3.at("VACBanned").get<bool>();
j3
doesn't have an element "VACBanned"
, so at("VACBanned")
likely returns nullptr
that you dereferenced.
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.