[PATCH] correct "JSON output format" without/with all class.

test pass on my machine.

Signed-off-by: Yuan-Chen Cheng <ycheng.tw@gmail.com>

Gbp-Pq: Name 82393aa9b59307a443677df7340a1dd38847a5ef.patch
This commit is contained in:
Yuan-Chen Cheng 2019-10-25 11:15:24 -04:00 committed by Lu zhiping
parent 4182469fa0
commit 20b636220b
1 changed files with 20 additions and 5 deletions

View File

@ -1653,13 +1653,29 @@ string hwNode::asJSON(unsigned level)
resources.clear();
}
for (unsigned int i = 0; i < countChildren(); i++)
if(countChildren()>0)
{
out << getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
if (visible(getChild(i)->getClassName()))
bool childOutputed = false;
for (unsigned int i = 0; i < countChildren(); i++)
{
out << "," << endl;
string childJSON = getChild(i)->asJSON(visible(getClassName()) ? level + 2 : 1);
string childJSONstrip = strip(childJSON);
if (childJSONstrip.length() > 0)
{
if (!childOutputed)
{
if(visible(getClassName()))
out << "," << endl << spaces(2*level+2) << "\"children\" : [" << endl;
}
else
out << "," << endl;
childOutputed = true;
out << childJSON;
}
}
if(visible(getClassName()) && childOutputed)
out << endl << spaces(2*level+2) << "]";
}
if(visible(getClassName()))
@ -1670,7 +1686,6 @@ string hwNode::asJSON(unsigned level)
if (level == 0)
{
out.seekp(-2, std::ios_base::end);
out << endl << "]" << endl;
}