How to access the value from the json file using runtime key in c++ #2714
Answered
by
nlohmann
RanjithaHosur
asked this question in
Q&A
-
I'm new to json and trying to use nlohmann library and I'm quite stuck. config.json file looks like this
I want to get the value of ["Map"]["1"] where "1" is a runtime entity. I have tried several ways but none of them is working.
I have also tried using the small json structure where I am not able to access the value using the runtime key.
Could any one help me. I am using C++11. |
Beta Was this translation helpful? Give feedback.
Answered by
nlohmann
Apr 19, 2021
Replies: 1 comment 5 replies
-
{
"Version": 1.1,
"Size": 1024,
"integer": 600,
"Map": [{"0": "india"}, {"1": "usa"}, {"2": "china"}, {"2": "japan"}],
"name": "xxx",
}
j["Map"][0]["1"] (assuming the input was parsed to |
Beta Was this translation helpful? Give feedback.
5 replies
Answer selected by
nlohmann
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Map
maps to an array of objects, so you need to access it via(assuming the input was parsed to
j
)