本文整理汇总了C++中JSONNode::GetString方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONNode::GetString方法的具体用法?C++ JSONNode::GetString怎么用?C++ JSONNode::GetString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONNode
的用法示例。
在下文中一共展示了JSONNode::GetString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
bool
ProgrammableOpAttributes::SetupPipeline(const JSONNode& atts, stringVector& args, const std::string& parent)
{
if(atts.GetType() != JSONNode::JSONARRAY)
return false;
const JSONNode::JSONArray& array = atts.GetArray();
for(int i = 0; i < array.size(); ++i)
{
/// need key, value pair
/// this can be in the form of a dictionary, "a = b", pair tuple (a,b), or a pair array [a,b]
JSONNode node = array[i];
JSONNode key,value;
if(node.GetType() == JSONNode::JSONARRAY)
{
if(node.GetArray().size() != 2) continue;
key = node.GetArray()[0];
value = node.GetArray()[1];
}
else if(node.GetType() == JSONNode::JSONOBJECT)
{
/// parse through dictionary and compute arguments from names..
const JSONNode::JSONObject& obj = node.GetJsonObject();
if(obj.size() != 1) continue;
const JSONNode::JSONObject::const_iterator itr = obj.begin();
key = itr->first;
value = itr->second;
}
else if(node.GetType() == JSONNode::JSONSTRING)
{
std::string pair = node.GetString();
int index = pair.find("=");
if(index == std::string::npos) continue;
key = pair.substr(0,index);
value = trim(pair.substr(index+1));
}
if(key.GetType() != JSONNode::JSONSTRING) continue;
std::string keystr = trim(key.GetString());
std::ostringstream str;
str << "import json\n";
if(value.GetType() == JSONNode::JSONSTRING)
{
std::string v = trim(value.GetString());
///character at 0 and has :
if(v.find(":") != std::string::npos && v.find(":") == 0)
{
/// optionally handle whether it can be as_vtkarray, as_ndarray, or as_rarray
size_t index = v.find(":as_ndarray");
if(index == std::string::npos)
index = v.find(":as_rarray");
if(index != std::string::npos)
{
std::string newName = getNextName();
v = v.substr(0,index);
AddNode(newName, "as_ndarray");
AddConnection(v, newName, "in");
AddConnection(newName,parent,keystr);
}
else
{
index = v.find(":as_vtkarray");
if(index != std::string::npos)
v = v.substr(0,index);
AddConnection(v,parent,keystr);
}
}
else
{
std::string escapedCode = trim(value.GetString());
replace(escapedCode,"\n","\\\n");
replace(escapedCode,"'","\"");
escapedCode = "'" + escapedCode + "'";
str << "try:\n"
<< " a = json.loads(" << escapedCode << ")\n"
<< "except:\n"
<< " a = " << escapedCode << "\n"
<< "setout(a)\n";
AddPythonScript(keystr,stringVector(),str.str());
AddNode(keystr,keystr);
AddConnection(keystr,parent,keystr);
}
}
else
{
str << "setout(json.loads('" << trim(value.ToString()) << "'))\n";
AddPythonScript(keystr,stringVector(),str.str());
//.........这里部分代码省略.........