Creating a objects within objects with a loop #4291
Unanswered
KojoBailey
asked this question in
Q&A
Replies: 1 comment 2 replies
-
This is not valid JSON. You have an object which contains only a single string.
This is the closest valid JSON to what you wrote.
This is another possibility, but you didn't provide the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
To put this simply, I have an
std::vector<std::string>
with values I don't know and a count of items I don't know.For example, this vector's values could be
{ "one", "two", "three", "four" }
.I want to have a loop that automatically creates a "chain" of objects-within-objects from this vector. Using the example vector from above, it should output the JSON:
Afterwards, I should be able to merge this JSON with other JSON generated from other vectors.
For example, if I have another vector which is
{ "one", "two", "three", "bazinga" }
, they should merge together to form:At least, that's what I understand from JSON. Maybe what I've outlined so far is wrong, in which case please tell me.
So, what I'm stuck on is the actual looping part. In my head, this is what I'm expecting from the above JSON (conceptualised in C++):
Although this creates an array (
[]
instead of{}
) for"four"
and"bazinga"
, which I don't want... I think? To be honest I'm not entirely sure how to go about achieving what I want. All I have at the moment is a vision and no clue where to start lolAny help? I can elaborate if need be
More specific contextual information...
I'm trying to create JSON from folder directories that lists all the files, folders, sub-folders, etc. in JSON format. Maybe there's a better solution to what I'm trying to achieve though than JSON? I just figured JSON would be the easiest to work with, but maybe I'm oblivious to something more vanilla and suited for C++ natively. I want to be able to access the data afterwords to construct custom MediaWiiki syntax stuff (not really relevant to my question though).Beta Was this translation helpful? Give feedback.
All reactions