-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Input several field with the same name #488
Comments
You can't have the same field more than once in the same object. You can have them in different objects, or you can have the field be an array which contains more than one value. |
just figured it out as well. never worked with json files before. Thank you! |
But what I dont get then is how I can input a variable amount of fields, like in the following snippet, where there is this [{ pair of brackets and the inner number of entries is put in by a for loop
|
|
thank you. I think I understood the general structure, but how can I produce a .json file that looks like your example, but has a varying number of these number pairs? My approach was to use a for-loop, but I cannot loop inside structures like this one here
|
There are a few ways to do this. You can build up the array at compile time, and insert it in one shot:
You can build it at runtime and insert it in one shot:
You can create the JSON array and insert things into it
|
Im not sure I can follow. I just cannot figure out how to typeset a structure like the one in your second last post |
Are you just referring to how to create text from the json object and how to format it? |
I guess so. However, I cannot make sense of it right now =/ |
Just think of |
well in a nutshell, I read in a json file into a json-object. Also I know how to access the individual elements inside this object. But I cant seem to figure out how to typeset then a file like above =/ maybe its just too late |
|
thanks but its not the indentation that puzzles me. Its the order of [{braces and how to fill it with the content |
That's the thing that I explained above that you said you already knew how to do. |
mh to be a little more discrete, I have the following json file (dont mind the exact numeric numbers)
that I want to transform into the format
I now tried the following in a .cpp file:
but ended up with this
|
Please use proper Markdown syntax. Add ``` (three backticks) before and after each code snippet. Otherwise, it is hard to parse your examples. |
I hope I set it correctly now ;and would appreciate help |
I was stupid, sorry for my annoying questions. Thats what happens if one doesnt stay in bed with fever. Everything is clear now, topic can be closed |
Thanks for checking back! |
How can I input more than one field with the same name, like often occuring in json files
`// create an empty structure (null)
json j;
// add a number that is stored as double (note the implicit conversion of j to an object)
j["pi"] = 3.141;
// add a second number that is stored as double (note the implicit conversion of j to an object)
j["pi"] = 3.14151;
it seems as if the first is just overwritten. Am I missing something here?
`
The text was updated successfully, but these errors were encountered: