Hello,
I'm trying to create a JSON structure that contains Arrays and Objects that are hierarchical. Could spend a considerable amount of time but thought I would post my questions first. I'm having issues creating Objects (key:value) pairs eg: "modelSeries":"520", within an Array. Also creating Arrays within Arrays. I'm attaching a JSON file that i'm working on and below is the code i've created so far. Hopefully someone can shed some light on the easiest way to do this.
Code:
// create an empty structure
json j;
// Update the template configuration version
std::string standardString = marshal_as<std::string>(hsConfig->getTemplateVersion());
j["headsetConfig"]["templateConfiguration"]["configTemplateVersion"] = standardString;
// Update the Timestamp
hsConfig->setUpdateTime(strTemp);
standardString = marshal_as<std::string>(hsConfig->getUpdateTime());
j["headsetConfig"]["templateConfiguration"]["updatedTime"] = standardString;
// Update the ReportId
standardString = marshal_as<std::string>(hsConfig->getReportId());
j["headsetConfig"]["templateConfiguration"]["reportId"] = standardString;
// Add the Model Specific array of models
json mSpecificSettings = j.array();
// Loop through the Models
// Set all the models for this series
json models = { "models" };
json mModelSeries;
for each(ModelSpecific^ ms in hsConfig->ModelSpecificList)
{
String^ s = ms->getModelSeries();
standardString = marshal_as<std::string>(s);
mModelSeries = { {"modelSeries", standardString } };
mSpecificSettings.push_back({ {"modelSeries", standardString } });
// Build the models array eg:521, 522, 523
json models250 = j.array();
for each(String^ mds in ms->modelList)
{
standardString = marshal_as<std::string>(mds);
models250.insert(models250.end(), standardString);
}
mSpecificSettings.push_back(models250);
//mModelSeries.insert(mModelSeries.end(), models250);
}
j["headsetConfig"]["templateConfiguration"]["modelSpecificSettings"] = mModelSeries;
// write prettified JSON to another file
std::ofstream o("pretty.json");
o << std::setw(4) << j << std::endl;
headsetJSON.zip
Hello,
I'm trying to create a JSON structure that contains Arrays and Objects that are hierarchical. Could spend a considerable amount of time but thought I would post my questions first. I'm having issues creating Objects (key:value) pairs eg: "modelSeries":"520", within an Array. Also creating Arrays within Arrays. I'm attaching a JSON file that i'm working on and below is the code i've created so far. Hopefully someone can shed some light on the easiest way to do this.
Code:
headsetJSON.zip