int jsonParse(string _s)
{
    // Let's parse it
    Json::Value root;
    Json::Reader reader;
    bool parsedSuccess = reader.parse(_s,
                                      root,
                                      false);

    if (not parsedSuccess) {
        // Report failures and their locations
        // in the document.
        cout << "Failed to parse JSON" << endl
             << reader.getFormatedErrorMessages()
             << endl;
        return 1;
    }

    Json::Value::Members mem = root.getMemberNames();
    Json::Value child = root[mem[0]];
    cout << "name: " << mem[0] << ", child: " << child.asString() << endl;
    for (int i = 1; i < mem.size(); ++i)
    {
        child = root[mem[i]];
        cout << "name: " << mem[i] << endl;
        Json::Value::Members childMem = child.getMemberNames();
        cout << "\t" << "type: " << child[childMem[0]].asString() << endl;
        cout << "\t" << "value: " << child[childMem[1]].asString() << endl;
        cout << "\t" << "typeGen: " << child[childMem[2]].asString() << endl;
    }
    return 1;
}
Exemple #2
0
  //Load skin
  bool Skin::load(const std::string& filename) {
    std::ifstream ifs(filename);
    std::string str((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());

    Json::Value root;
    Json::Reader reader;

    m_classes.clear();

    if (!reader.parse(str, root)) {
      return false;
    }

    Json::Value::Members classes = root.getMemberNames();
    for (uint32 i = 0; i < classes.size(); i++) {
      std::string name = classes[i];
      Json::Value v = root[name];

      Skin::SkinClass sc;

      bool addP = false;

      //We need to figure out if we're dealing with sub classes.
      Json::Value::Members subs = v.getMemberNames();
      for (uint32 j = 0; j < subs.size(); j++) {
        if (subs[j] != "normal" && subs[j] != "hover" && subs[j] != "active" && subs[j] != "focus") {
          //Yup, this is a sub class.
          Skin::SkinClass sub;
          jsonToStates(v[subs[j]], sub);

          sc.m_subs.insert(ClassMapPair(subs[j], sub));

        } else {
          addP = true;
        }
      }

      //There's a valid state in the root
      if (addP) {
        jsonToStates(v, sc);
      }

      sc.reset();
      m_classes.insert(ClassMapPair(name, sc));
    }

    m_loaded = filename;

    return true;
  }
Exemple #3
0
int CCardFieldDlg::load_card_right_json()
{
	int i,idx;
	Json::Value root;
	Json::Reader reader;
	std::ifstream input;
	//input.open("e:\\works\\cardlib\\ykt.v3_1.dev\\bin\\lcsmanager\\cardright.json");
	input.open((LPCTSTR)m_jsonfile);
	if(input.is_open()==false)
	{
		AfxMessageBox("´ò¿ªÅäÖÃÎļþ´íÎó");
		return -1;
	}
	if(reader.parse(input,root)==false)
	{
		std::string msg = "¶ÁÈ¡ÅäÖÃÎļþ´íÎó : " + reader.getFormatedErrorMessages();
		AfxMessageBox(msg.c_str());
		return -1;
	}
	std::string encoding = root.get("encoding","GBK").asString();
	Json::Value fields = root["cardfield"];
	Json::Value::Members fldid = fields.getMemberNames();
	m_cardfield.clear();
	for(i = 0;i < fldid.size();++i)
	{
		idx = atoi(fldid[i].c_str());
		std::string v = fields.get(fldid[i],"Unknown").asString();
		m_cardfield.insert(CARD_FILED_MAP::value_type(idx,v));
	}
	if(fldid.size() > m_string_len)
		m_string_len = fldid.size();
//	std::sort(m_cardfield.begin(),m_cardfield.end());
	init_check_box();
	return 0;
}
void JsonParameters::importParameters(Json::Value parametersImport)
{
    if (parametersImport.isObject()) {
        Json::Value::Members members = parametersImport.getMemberNames();
        Json::Value::Members::iterator it;

        for (it=members.begin(); it!=members.end(); it++) {
            string name = *it;
            JsonParameter *parameter = getParameter(name);
            if (parameter != NULL) {
                if (parameter->canDeserialize(parametersImport[name])) {
                    parameter->deserialize(parametersImport[name]);
                } else {
                    std::cerr << "Can't load parameter " << name << std::endl;
                }
            } else {
                std::cerr << "Non-existent parameter: " << name << std::endl;
            }
        }
    } else {
        if (!parametersImport.isNull()) {
            std::cerr << "Parameters values should be an object" << std::endl;
        }
    }
}
/**
 * Constructor 
 * @param equipletID identifier for the equiplet
 * @param moduleID identifier for the deltarobot
 **/
stewartGoughNodeNamespace::StewartGoughNode::StewartGoughNode(std::string equipletName, rexos_datatypes::ModuleIdentifier moduleIdentifier) :
		rexos_module::ActorModule::ActorModule(equipletName, moduleIdentifier),
		stewartGough(NULL),
		lastX(0.0),
		lastY(0.0),
		lastZ(0.0){
	REXOS_INFO("StewartGoughNode Constructor entering...");
	// get the properties and combine them for the deltarobot
	std::string properties = this->getModuleProperties();
	std::string typeProperties = this->getModuleTypeProperties();


	Json::Reader reader;
	Json::Value jsonNode;
	Json::Value typeJsonNode;
	reader.parse(properties, jsonNode);
	reader.parse(typeProperties, typeJsonNode);
	
	std::vector<std::string> typeJsonNodeMemberNames = typeJsonNode.getMemberNames();
	for(int i = 0; i < typeJsonNodeMemberNames.size(); i++) {
		jsonNode[typeJsonNodeMemberNames[i]] = typeJsonNode[typeJsonNodeMemberNames[i]];
	}

	Json::StyledWriter writer;
	ROS_INFO("%s", writer.write(jsonNode).c_str());
		
	// Create a stewart gough robot
	stewartGough = new rexos_stewart_gough::StewartGough(jsonNode);
}
Exemple #6
0
StateLoader::StateLoader(Json::Value const& _json, std::string const& _dbPath):
	m_state(State::openDB(_dbPath, WithExisting::Kill), BaseState::Empty)
{
	for (string const& name: _json.getMemberNames())
	{
		Json::Value o = _json[name];

		Address address = Address(name);
		bytes code = fromHex(o["code"].asString().substr(2));

		if (!code.empty())
		{
			m_state.m_cache[address] = Account(u256(o["balance"].asString()), Account::ContractConception);
			m_state.m_cache[address].setCode(std::move(code));
		}
		else
			m_state.m_cache[address] = Account(u256(o["balance"].asString()), Account::NormalCreation);

		for (string const& j: o["storage"].getMemberNames())
			m_state.setStorage(address, u256(j), u256(o["storage"][j].asString()));

		for (auto i = 0; i < u256(o["nonce"].asString()); ++i)
			m_state.noteSending(address);

		m_state.ensureCached(address, false, false);
	}

	m_state.commit();
}
void SceneLoader::Load(const char* strFileName, GameObject *rootGameObject)
{
	GameObject *pGo = 0;
	Json::Value root;
	Json::Reader reader;

	const char* jsonText = ReadFileIntoString( strFileName );

	if( !reader.parse( jsonText, root ) )
	{
		return;
	}


	Json::Value componentsVal = root["objects"];
	int componentCount = componentsVal.size();

	for( int i=0; i< componentCount; ++i )
	{
		Json::Value componentVal = componentsVal[i];
		Json::Value::Members members = componentVal.getMemberNames();
		
		std::map<std::string, std::string> mapParams;
		for( Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it)
		{
			std::string memberName = *it;
			std::string value = componentVal[memberName].asString();

			mapParams[memberName] = value;
		}

		CreateSceneObject( rootGameObject, mapParams );
	}
}
void emailExtraction::parseEmailForInbox(Json::Value value, std::string folder) {
    Json::Value directoryObj = value[folder];
    std::vector<std::string> objNames = directoryObj.getMemberNames();
    for (unsigned int i = 0; i < directoryObj.size(); i++) {
        auto contentObj = directoryObj[objNames[i]];
        std::string objName = objNames[i];
        if(contentObj.size() > 0) {
            parseEmailForInbox(directoryObj, objNames[i]);
        }
        else {
            std::string content = directoryObj[objNames[i]].asString();
            //std::cout << objName+""+content << std::endl;
            if(objName == "Subject") {
                addSubject(content);
            }
            else if(objName == "To") {
                addTo(content);
            }
            else if(objName == "From") {
                addFrom(content);
            }
            else if(objName == "Body") {
                addBody(content);
            }
            else if(objName == "Visible") {
                addVisible(content.at(0) == '1');
            }
            else {
                std::cout << "ERROR" << std::endl;
            }
        }
    }
}
Exemple #9
0
Options PipelineReaderJSON::extractOptions(Json::Value& node)
{
    Options options;

    for (const std::string& name : node.getMemberNames())
    {
        if (node[name].isString())
            options.add(name, node[name].asString());
        else if (node[name].isInt())
            options.add(name, node[name].asInt64());
        else if (node[name].isUInt())
            options.add(name, node[name].asUInt64());
        else if (node[name].isDouble())
            options.add(name, node[name].asDouble());
        else if (node[name].isBool())
            options.add(name, node[name].asBool());
        else if (node[name].isNull())
            options.add(name, "");
        else
            throw pdal_error("JSON pipeline: Value of stage option '" +
                name + "' cannot be converted.");
    }
    node.clear();
    return options;
}
Exemple #10
0
RegexpData::RegexpData() {
    Json::Value root = loadJSONFile(RegexpData::REGEXPS_FILE);

    for(const auto& key: root.getMemberNames()) {
        m_regexpMap[key] = root[key].asString();
    }
}
Exemple #11
0
RecordPtr Common::assembleRecord(const Json::Value& rVal)
{
  auto contact = rVal["contact"].asString();
  auto nonce = rVal["nonce"].asString();
  auto pow = rVal["pow"].asString();
  auto pubHSKey = rVal["pubHSKey"].asString();
  auto sig = rVal["recordSig"].asString();
  auto type = rVal["type"].asString();
  auto name = rVal["name"].asString();

  if (type != "Create")
    Log::get().error("Record parsing: not a Create Record!");

  NameList subdomains;
  if (rVal.isMember("subd"))
  {
    Json::Value list = rVal["subd"];
    auto sources = list.getMemberNames();
    for (auto source : sources)
      subdomains.push_back(std::make_pair(source, list[source].asString()));
  }

  auto key = Utils::base64ToRSA(pubHSKey);
  return std::make_shared<CreateR>(contact, name, subdomains, nonce, pow, sig,
                                   key);
}
        //---------------------------------------------------------------
        //---------------------------------------------------------------
        void GooglePlayIAPJavaInterface::StartListeningForTransactionUpdates(const CSNetworking::IAPSystem::TransactionStatusDelegate& in_delegate)
        {
        	CS_ASSERT(in_delegate != nullptr, "Cannot have null transaction delegate");

        	m_transactionStatusDelegate = in_delegate;

        	JNIEnv* env = JavaInterfaceManager::GetSingletonPtr()->GetJNIEnvironmentPtr();
        	env->CallVoidMethod(GetJavaObject(), GetMethodID("RestorePendingUnmanagedTransactions"));

        	Json::Value jData;
        	if(CSCore::JsonUtils::ReadJson(CSCore::StorageLocation::k_cache, k_pendingCacheFile, jData))
        	{
        		const Json::Value::Members& members = jData.getMemberNames();
        		jobjectArray transactionIDs = env->NewObjectArray(members.size(), env->FindClass("java/lang/String"), env->NewStringUTF(""));

        		u32 index = 0;
        		for(Json::Value::Members::const_iterator it = members.begin(); it != members.end(); ++it, ++index)
        		{
    				jstring jtransactionId = JavaInterfaceUtils::CreateJStringFromSTDString(*it);
    				env->SetObjectArrayElement(transactionIDs, index, jtransactionId);
    				env->DeleteLocalRef(jtransactionId);
        		}

            	env->CallVoidMethod(GetJavaObject(), GetMethodID("RestorePendingManagedTransactions"), transactionIDs);
            	env->DeleteLocalRef(transactionIDs);
        	}
        }
	void EnvironmentCache::mergeJsonNode(Json::Value& toBeMerged, Json::Value& mergeTarget) {
#ifdef ENVIRONMENT_CACHE_DEBUG
		ROS_DEBUG_STREAM("Merging json nodes, toBeMerged: " << toBeMerged << " mergeTerget: " << mergeTarget);
#endif
		std::vector<std::string> memberNames = toBeMerged.getMemberNames();
		
		for(int i = 0; i < memberNames.size(); i++) {
#ifdef ENVIRONMENT_CACHE_DEBUG
		ROS_DEBUG_STREAM("Merging member " << memberNames[i]);
#endif
			if(toBeMerged[memberNames[i]].type() == Json::ValueType::objectValue) {
#ifdef ENVIRONMENT_CACHE_DEBUG
		ROS_DEBUG_STREAM("Member is JsonObject");
#endif
				mergeJsonNode(toBeMerged[memberNames[i]], mergeTarget[memberNames[i]]);
			} else {
#ifdef ENVIRONMENT_CACHE_DEBUG
		ROS_DEBUG_STREAM("Member is not JsonObject");
#endif
				mergeTarget[memberNames[i]] = toBeMerged[memberNames[i]];
			}
		}
#ifdef ENVIRONMENT_CACHE_DEBUG
		ROS_DEBUG_STREAM("Merge result " << mergeTarget);
#endif
	}
FB::variant jsonValueToVariant( Json::Value root )
{
    Json::Value def;
    if (root.isString())
        return root.asString();
    else if (root.isBool())
        return root.asBool();
    else if (root.isDouble())
        return root.asDouble();
    else if (root.isInt())
        return root.asInt();
    else if (root.isUInt())
        return root.asUInt();
    else if (root.isNull())
        return FB::FBNull();
    else if (root.isArray()) {
        FB::VariantList outList;
        for (size_t i = 0; i < root.size(); ++i) {
            outList.push_back(jsonValueToVariant(root.get(i, def)));
        }
        return outList;
    } else if (root.isObject()) {
        Json::Value::Members members = root.getMemberNames();
        FB::VariantMap outMap;
        for (Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it)
        {
            outMap[*it] = jsonValueToVariant(root.get(*it, def));
        }
        return outMap;
    } else {
        return FB::FBVoid();
    }
}
/* ---------------------------------------------------------------- */
void diplayRemotes()
{
	Value::Members members = jsonRoot.getMemberNames();
	for (std::vector<string>::iterator it = members.begin(); it != members.end(); ++it) 
		if (string::npos != (*it).find("remote_"))
			cout << "  " << *it << endl;
}
	VMResultArray<TESObjectREFR*> getActiveDisplays(StaticFunctionTag*, BSFixedString characterName)
	{
		VMResultArray<TESObjectREFR*> results;
		Json::Value jsonDisplayList = ReadDisplayData();

		for (auto & jsonDisplay : jsonDisplayList.getMemberNames()) 
		{
			TESObjectREFR* displayObj = DYNAMIC_CAST(GetJCStringForm(jsonDisplay), TESForm, TESObjectREFR);
			
			if (strlen(characterName.data))
			{
				for (auto & contributor : jsonDisplayList[jsonDisplay.c_str()]["contributors"])
				{
					if (contributor.asString() == characterName.data)
						results.push_back(displayObj);
				}
			} 
			else 
			{
				results.push_back(displayObj);
			}
		}
		
		return results;
	}
//-----------------------------------------------------------------------------------
void EngineConfig::LoadSceneSettings(Json::Value root, Json::Reader reader)
{
	Json::Value settings = root["scenes"];
	int componentCount = settings.size();

	for( int i=0; i< componentCount; ++i )
	{
		Json::Value componentVal = settings[i];
		Json::Value::Members members = componentVal.getMemberNames();

		map<std::string, std::string> mapValues;
		for( Json::Value::Members::iterator it = members.begin(); it != members.end(); ++it)
		{
			std::string memberName = *it;
			std::string value = componentVal[memberName].asString();
			
			mapValues[memberName] = value;

		}

		std::string sceneName = mapValues["name"];
		std::string fileName = mapValues["file"];

		SceneData *sceneData = new SceneData( sceneName, fileName );

		scenes[sceneName] = sceneData;
	}

	settings = root["startscene"];
	startScene = scenes[settings.asCString()];
}
Exemple #18
0
/** Set the ordered list of properties by a json value collection
 *
 *  @param jsonValue :: The jsonValue of property values
 *  @param ignoreProperties :: A set of names of any properties NOT to set
 *      from the propertiesArray
 *  @param targetPropertyManager :: the propertymanager to make the changes to,
 *      most of the time this will be *this
 */
void PropertyManager::setProperties(
    const ::Json::Value &jsonValue, IPropertyManager *targetPropertyManager,
    const std::set<std::string> &ignoreProperties) {
  if (jsonValue.type() == ::Json::ValueType::objectValue) {

    // Some algorithms require Filename to be set first do that here
    const std::string propFilename = "Filename";
    ::Json::Value filenameValue = jsonValue[propFilename];
    if (!filenameValue.isNull()) {
      const std::string value = jsonValue[propFilename].asString();
      // Set it
      targetPropertyManager->setPropertyValue(propFilename, value);
    }

    for (::Json::ArrayIndex i = 0; i < jsonValue.size(); i++) {
      const std::string propName = jsonValue.getMemberNames()[i];
      if ((propFilename != propName) &&
          (ignoreProperties.find(propName) == ignoreProperties.end())) {
        ::Json::Value propValue = jsonValue[propName];
        const std::string value = propValue.asString();
        // Set it
        targetPropertyManager->setPropertyValue(propName, value);
      }
    }
  }
}
Exemple #19
0
void WizCommonApiEntry::getEndPoints()
{
    QMutexLocker locker(&m_mutex);
    //
    QString urls = requestUrl("endpoints");
#ifdef QT_DEBUG
    qDebug() << "get end points : " << urls;
#endif
    if (urls.isEmpty() || !urls.contains("http"))
        return;

    Json::Value d;
    Json::Reader reader;
    if (!reader.parse(urls.toUtf8().constData(), d))
        return;
    //
    Json::Value::Members keys = d.getMemberNames();

    for(auto keyStr : keys)
    {
        QString key = QString::fromStdString(keyStr);
        QString url = QString::fromStdString(d[keyStr].asString());
#ifdef QT_DEBUG
        qDebug() << "key: " << key << " url : " << url;
#endif
        m_cacheMap.insert(key, url);
    }
}
Exemple #20
0
bool KsCardMsg::parseJsonData(const std::string& rootname,Json::Value &root)
{
	size_t i;
	Json::Value::Members mbs = root.getMemberNames();
	++parseLevel_;
	if(parseLevel_>2)
		return false;
	for(i = 0;i < mbs.size(); ++i)
	{
		Json::Value& clt = root[mbs[i]];
		std::string fullname = rootname;
		if(rootname.length() > 0)
			 fullname += ".";
		fullname += mbs[i];
		if(clt.isArray() || clt.isObject())
		{
			if(!parseJsonData(fullname,clt))
				return false;
		}
		else
		{
			msg_field_.insert(PARA_MAP_TYPE::value_type(fullname,root.get(mbs[i],"").asString()));
		}
	}
	return true;
}
Exemple #21
0
Kiblet::Kiblet(Json::Value& v) {
	Json::Value::Members& members = v.getMemberNames();
	for (unsigned int i = 0; i < members.size(); ++i) {
		Kidget* k = makeKidget(members[i], v[members[i]]);
		kidgets.push_back(k);
	}
}
Exemple #22
0
 static void add(
     MetadataNode&      parent,
     const std::string& name,
     const Json::Value& node
 )
 {
     if      (node.isNull())   { parent.add(name, ""); }
     else if (node.isBool())   { parent.add(name, node.asBool()); }
     else if (node.isInt())    { parent.add(name, node.asInt64()); }
     else if (node.isUInt())   { parent.add(name, node.asUInt64()); }
     else if (node.isDouble()) { parent.add(name, node.asDouble()); }
     else if (node.isString()) { parent.add(name, node.asString()); }
     else if (node.isObject())
     {
         MetadataNode object = parent.add(name);
         for (const std::string& name: node.getMemberNames())
         {
             add(object, name, node[name]);
         }
     }
     else if (node.isArray())
     {
         for (const Json::Value& item: node)
         {
             add(parent, name, item);
         }
     }
 }
  GameObject * Factory::BuildJsonComposition(const char *file)
  {
    // Open the Json file and read in the components:
    Json::Value components = GetJsonRoot(file)["Components"];
    ErrorIf(!components, "Failed to open file %s.", file);
    std::vector<std::string> componentList = components.getMemberNames();

    GameObject *gameObject = new GameObject();

    // Add each of the components to the new object:
    for (unsigned i = 0; i < components.size(); ++i)
    {
      // 1. Check if the component is registered and has a creator
      //    in the component map:
      ComponentCreatorMap::iterator it = 
        componentCreatorMap_.find(componentList.at(i));
      ErrorIf(it == componentCreatorMap_.end(), "Failed to create unregistered component %s", componentList.at(i));

      // 2. Create a new component once the creator is found in the
      //    map:
      ComponentCreator *creator = it->second;
      Component *component = creator->Create();

      // 3. Serialize the component using the Json value in the file:
      component->Deserialize(components[componentList.at(i)]);

      // 4. Add the component to the composition:
      gameObject->AddComponent(creator->TypeId, component);
    }

    IdGameObject(gameObject);

    return gameObject;
  }
/**
 * Updates a configuration map with the given json node.
 *
 * @param configurationMap The configuration map to be updated.
 * @param currentNode The node to be used to update the configuration map.
 */
void JsonConfigurationParser::updateConfigurationMap(ConfigurationMap *configurationMap, const Json::Value &currentNode) {
    // retrieves the menber names
    Json::Value::Members currentNodeMembers = currentNode.getMemberNames();

    // retrieves the current node members iterator
    Json::Value::Members::iterator currentNodeMembersIterator = currentNodeMembers.begin();

    // itearates over all the current node members
    while(currentNodeMembersIterator != currentNodeMembers.end()) {
        // retrieves the property name
        std::string &propertyName = *currentNodeMembersIterator;

        // retrieves the property value
        Json::Value propertyValue = currentNode[propertyName];

        // creates the configuration value
        ConfigurationValue *configurationValue = this->createConfigurationValue(propertyValue);

        // sets the propery in the configuration map
        configurationMap->setProperty(propertyName, configurationValue);

        // increments the current node members iterator
        currentNodeMembersIterator++;
    }
}
Exemple #25
0
configGoodsItem*  CData::getConfigOfGoods(int tempid)
{
    
    if(m_config_goods_dic->count() < 1)
    {
//        const char * path=FileUtils::getInstance()->fullPathForFilename("itemconfig.json").c_str();
//        ifstream ifs;
//        ifs.open(path);
//        assert(ifs.is_open());
        Json::Reader reader;
        Json::Value root;
        Json::Value items;
        
        Json::Value::Members members;
        
//        Json::Value::iterator it;
        Json::Value::Members::iterator it;
        
        string path = FileUtils::getInstance()->fullPathForFilename("item.json");
        __String* str = __String::createWithContentsOfFile(path.c_str());
            
        if(reader.parse(str->getCString(), root)){
            
            members = root.getMemberNames();
            it = members.begin();
            while (it != members.end()) {
                
                items = root[std::string(*it)];
                
                configGoodsItem * item= new configGoodsItem();
                char inttostr[20]="";
                sprintf(inttostr, "%d",tempid);
                
                item->bodytype=items["bodyType"].asInt();
                item->name=items["name"].asString();
                item->pinzhi=items["baseQuality"].asInt();
                item->des=items["description"].asString();
                item->tempid = items["id"].asInt();
                item->icon = items["icon"].asInt();
                item->maxexp = items["maxexp"].asInt();
                item->growTemp = items["growTemp"].asInt();
                item->comprice = items["comprice"].asInt();
                item->compound = items["compound"].asInt();
                
                
                m_config_goods_dic->setObject(item, item->tempid);
                
                it++;
            }
        
         //   ifs.close();
    
        }

    }
    
    
    return (configGoodsItem*)m_config_goods_dic->objectForKey(tempid);
    
}
Exemple #26
0
bool CTestjsoncpp::test_Parse()
{
	std::wstring wstrJson = ReleaseJsonStr();
	std::string strJson = wstr2str(wstrJson, CP_UTF8);
	Json::Reader jsonReader;
	Json::Value root;
	jsonReader.parse(strJson, root);

	std::string strresult = root["result"].asString();
	std::cout << "result:" << strresult << std::endl;

	std::cout << "data:" << std::endl;
	Json::Value jvData = root["data"];
	if(jvData.isArray())
	{
		std::cout << "[" << std::endl;
		//item
		for (Json::Value::iterator it = jvData.begin(); it != jvData.end(); ++it)
		{
			std::cout << "{" << std::endl;
			Json::Value item = *it;
			Json::Value::Members memItem = item.getMemberNames();
			//mem in item
			for (Json::Value::Members::iterator itItem = memItem.begin(); itItem != memItem.end(); ++itItem)
			{
				std::string strKey = *itItem;
				std::string strValue = item[strKey].asString();
				std::cout << strKey << ":" << strValue << std::endl;
			}
			std::cout << "}" << std::endl;
		}
		std::cout << "]" << std::endl;
	}
	return false;
}
Exemple #27
0
    void SimplifyTags(Json::Value& target,
                      const Json::Value& source,
                      DicomToJsonFormat format)
    {
      assert(source.isObject());

      target = Json::objectValue;
      Json::Value::Members members = source.getMemberNames();

      for (size_t i = 0; i < members.size(); i++)
      {
        const Json::Value& v = source[members[i]];
        const std::string& type = v["Type"].asString();

        std::string name;
        switch (format)
        {
          case DicomToJsonFormat_Human:
            name = v["Name"].asString();
            break;

          case DicomToJsonFormat_Short:
            name = members[i];
            break;

          default:
            throw OrthancException(ErrorCode_ParameterOutOfRange);
        }

        if (type == "String")
        {
          target[name] = v["Value"].asString();
        }
        else if (type == "TooLong" ||
                 type == "Null")
        {
          target[name] = Json::nullValue;
        }
        else if (type == "Sequence")
        {
          const Json::Value& array = v["Value"];
          assert(array.isArray());

          Json::Value children = Json::arrayValue;
          for (Json::Value::ArrayIndex i = 0; i < array.size(); i++)
          {
            Json::Value c;
            SimplifyTags(c, array[i], format);
            children.append(c);
          }

          target[name] = children;
        }
        else
        {
          assert(0);
        }
      }
    }
Exemple #28
0
void check_json_object(Json::Value const & object,
    std::set<std::string> const & expected_members)
{
    BOOST_REQUIRE(object.isObject());
    auto const members = object.getMemberNames();
    BOOST_REQUIRE(
        std::set<std::string>(members.begin(), members.end()) == expected_members);
}
Exemple #29
0
inline void recMerge(Json::Value& dst, const Json::Value& add)
{
    for (const auto& key : add.getMemberNames())
    {
        if (add[key].isObject()) recMerge(dst[key], add[key]);
        else dst[key] = add[key];
    }
}
Exemple #30
0
static void
printValueTree( FILE *fout, Json::Value &value, const std::string &path = "." )
{
   switch ( value.type() )
   {
   case Json::nullValue:
      fprintf( fout, "%s=null\n", path.c_str() );
      break;
   case Json::intValue:
      fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestInt() ).c_str() );
      break;
   case Json::uintValue:
      fprintf( fout, "%s=%s\n", path.c_str(), Json::valueToString( value.asLargestUInt() ).c_str() );
      break;
   case Json::realValue:
       fprintf( fout, "%s=%s\n", path.c_str(), normalizeFloatingPointStr(value.asDouble()).c_str() );
      break;
   case Json::stringValue:
      fprintf( fout, "%s=\"%s\"\n", path.c_str(), value.asString().c_str() );
      break;
   case Json::booleanValue:
      fprintf( fout, "%s=%s\n", path.c_str(), value.asBool() ? "true" : "false" );
      break;
   case Json::arrayValue:
      {
         fprintf( fout, "%s=[]\n", path.c_str() );
         int size = value.size();
         for ( int index =0; index < size; ++index )
         {
            static char buffer[16];
#if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__)
            sprintf_s( buffer, sizeof(buffer), "[%d]", index );
#else
            snprintf( buffer, sizeof(buffer), "[%d]", index );
#endif
            printValueTree( fout, value[index], path + buffer );
         }
      }
      break;
   case Json::objectValue:
      {
         fprintf( fout, "%s={}\n", path.c_str() );
         Json::Value::Members members( value.getMemberNames() );
         std::sort( members.begin(), members.end() );
         std::string suffix = *(path.end()-1) == '.' ? "" : ".";
         for ( Json::Value::Members::iterator it = members.begin(); 
               it != members.end(); 
               ++it )
         {
            const std::string &name = *it;
            printValueTree( fout, value[name], path + suffix + name );
         }
      }
      break;
   default:
      break;
   }
}