本文整理汇总了C++中JsonObject::Print方法的典型用法代码示例。如果您正苦于以下问题:C++ JsonObject::Print方法的具体用法?C++ JsonObject::Print怎么用?C++ JsonObject::Print使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonObject
的用法示例。
在下文中一共展示了JsonObject::Print方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
smatch jLineMatch;
smatch jValMatch;
string jsonID;
string jsonVal;
bool openBraceNotFound = true;
// temp variables for valid types found
int jInt;
string jStr;
bool jBool;
string jNull = "null";
// json objects
JsonObject* jObject = new JsonObject();
JsonArray * jArray = new JsonArray();
do {
getline(inFile, buf);
// check for empty line
if(regex_search(buf, jLineMatch, emptyRE)) {
cout << "empty line...\n";
continue;
}
// check for open brace
if(regex_search(buf, jLineMatch, openBraceRE)) {
openBraceNotFound = false;
continue;
}
// if the first character is not a brace display error and exit
if (openBraceNotFound) {
cout <<"ERROR expected {...\n";
exit(1);
}
// check for close brace
if(regex_search(buf, jLineMatch, closeBraceRE)) {
break;
}
// if valid line found, save id and value
if(regex_search(buf, jLineMatch, jLineRE))
{
jsonID = jLineMatch.str(1);
jsonVal = jLineMatch.str(2);
}
// if valid line not found, put an error and exit
else {
cout << "\nERROR: Not a valid line! \n";
exit(1);
}
// if valid array found add too the object
if (regex_search(jsonVal, jValMatch, arrayRE)) {
cout << "Array matched!\n";
jArray->Add(new JsonString(jLineMatch.str(1)));
jObject->Add(jsonID, jArray);
}
// if valid integer found add it too the object
else if (regex_search(jsonVal, jValMatch, jIntRE)) {
jInt = stoi(jsonVal);
cout << "Valid Int " << jInt << " matched! \n";
jObject->Add(jsonID, new JsonNumber(jInt));
}
// if valid string found, add it to the object
else if (regex_search(jsonVal, jValMatch, jStrRE)) {
jStr = jValMatch.str(1);
cout << "Valid String " << jStr << " matched! \n";
jObject->Add(jsonID, new JsonString(jStr));
}
// finally look for bool or null
else if(regex_search(jsonVal, jValMatch, jBoolorNullRE)) {
if ("true" == jValMatch.str(1)) {
jBool = true ;
cout << "Valid bool " << jBool << " matched! \n";
jObject->Add(jsonID, new JsonBoolean(jBool));
}
else if ("false" == jValMatch.str(1)){
jBool = false ;
cout << "Valid bool " << jBool << " matched! \n";
jObject->Add(jsonID, new JsonBoolean(jBool));
}
else if ("null" == jValMatch.str(1)){
cout << "Valid null matched! \n";
jObject->Add(jsonID, new JsonNull());
}
}
// if the line from file contains anything else then exit
else {
cout << "Error invalid value...\n";
exit(1);
}
} while (!inFile.eof());
cout << endl;
jObject->Print();
cout << endl;
return 0;
}