本文整理汇总了C++中JSONValue::Get方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONValue::Get方法的具体用法?C++ JSONValue::Get怎么用?C++ JSONValue::Get使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONValue
的用法示例。
在下文中一共展示了JSONValue::Get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadJSON
bool ValueAnimation::LoadJSON(const JSONValue& source)
{
valueType_ = VAR_NONE;
eventFrames_.Clear();
String interpMethodString = source.Get("interpolationmethod").GetString();
InterpMethod method = (InterpMethod)GetStringListIndex(interpMethodString.CString(), interpMethodNames, IM_LINEAR);
SetInterpolationMethod(method);
if (interpolationMethod_ == IM_SPLINE)
splineTension_ = source.Get("splinetension").GetFloat();
// Load keyframes
JSONArray keyFramesArray = source.Get("keyframes").GetArray();
for (unsigned i = 0; i < keyFramesArray.Size(); i++)
{
const JSONValue& val = keyFramesArray[i];
float time = val.Get("time").GetFloat();
Variant value = val.Get("value").GetVariant();
SetKeyFrame(time, value);
}
// Load event frames
JSONArray eventFramesArray = source.Get("eventframes").GetArray();
for (unsigned i = 0; i < eventFramesArray.Size(); i++)
{
const JSONValue& eventFrameVal = eventFramesArray[i];
float time = eventFrameVal.Get("time").GetFloat();
unsigned eventType = eventFrameVal.Get("eventtype").GetUInt();
VariantMap eventData = eventFrameVal.Get("eventdata").GetVariantMap();
SetEventFrame(time, StringHash(eventType), eventData);
}
return true;
}
示例2: LoadJSON
bool Animatable::LoadJSON(const JSONValue& source, bool setInstanceDefault)
{
if (!Serializable::LoadJSON(source, setInstanceDefault))
return false;
SetObjectAnimation(0);
attributeAnimationInfos_.Clear();
JSONValue value = source.Get("objectanimation");
if (!value.IsNull())
{
SharedPtr<ObjectAnimation> objectAnimation(new ObjectAnimation(context_));
if (!objectAnimation->LoadJSON(value))
return false;
SetObjectAnimation(objectAnimation);
}
JSONValue attributeAnimationValue = source.Get("attributeanimation");
if (attributeAnimationValue.IsNull())
return true;
if (!attributeAnimationValue.IsObject())
{
URHO3D_LOGWARNING("'attributeanimation' value is present in JSON data, but is not a JSON object; skipping it");
return true;
}
const JSONObject& attributeAnimationObject = attributeAnimationValue.GetObject();
for (JSONObject::ConstIterator it = attributeAnimationObject.Begin(); it != attributeAnimationObject.End(); it++)
{
String name = it->first_;
JSONValue value = it->second_;
SharedPtr<ValueAnimation> attributeAnimation(new ValueAnimation(context_));
if (!attributeAnimation->LoadJSON(it->second_))
return false;
String wrapModeString = source.Get("wrapmode").GetString();
WrapMode wrapMode = WM_LOOP;
for (int i = 0; i <= WM_CLAMP; ++i)
{
if (wrapModeString == wrapModeNames[i])
{
wrapMode = (WrapMode)i;
break;
}
}
float speed = value.Get("speed").GetFloat();
SetAttributeAnimation(name, attributeAnimation, wrapMode, speed);
it++;
}
return true;
}
示例3: LoadSettingsInternal
bool TypeScriptImporter::LoadSettingsInternal(JSONValue& jsonRoot)
{
if (!AssetImporter::LoadSettingsInternal(jsonRoot))
return false;
JSONValue import = jsonRoot.Get("TypeScriptImporter");
isComponentFile_ = import.Get("IsComponentFile").GetBool();
return true;
}
示例4: Read
void WebBuildSettings::Read(JSONValue& parent)
{
JSONValue json = parent.Get("WebBuildSettings");
if (!json.IsObject())
return;
appName_ = json.Get("appName").GetString();
packageName_ = json.Get("packageName").GetString();
companyName_ = json.Get("companyName").GetString();
productName_ = json.Get("productName").GetString();
}
示例5: LoadSettingsInternal
bool TextureImporter::LoadSettingsInternal(JSONValue& jsonRoot)
{
if (!AssetImporter::LoadSettingsInternal(jsonRoot))
return false;
JSONValue import = jsonRoot.Get("TextureImporter");
SetDefaults();
if (import.Get("compressionSize").IsNumber())
compressedSize_ = (CompressedFormat)import.Get("compressionSize").GetInt();
return true;
}
示例6: LoadJSON
bool UnknownComponent::LoadJSON(const JSONValue& source, bool setInstanceDefault)
{
useXML_ = true;
xmlAttributes_.Clear();
xmlAttributeInfos_.Clear();
binaryAttributes_.Clear();
JSONArray attributesArray = source.Get("attributes").GetArray();
for (unsigned i = 0; i < attributesArray.Size(); i++)
{
const JSONValue& attrVal = attributesArray.At(i);
AttributeInfo attr;
attr.mode_ = AM_FILE;
attr.name_ = attrVal.Get("name").GetString();
attr.type_ = VAR_STRING;
if (!attr.name_.Empty())
{
String attrValue = attrVal.Get("value").GetString();
attr.defaultValue_ = String::EMPTY;
xmlAttributeInfos_.Push(attr);
xmlAttributes_.Push(attrValue);
}
}
// Fix up pointers to the attributes after all have been read
for (unsigned i = 0; i < xmlAttributeInfos_.Size(); ++i)
xmlAttributeInfos_[i].ptr_ = &xmlAttributes_[i];
return true;
}
示例7: LoadSettingsInternal
bool CSharpImporter::LoadSettingsInternal(JSONValue& jsonRoot)
{
if (!AssetImporter::LoadSettingsInternal(jsonRoot))
return false;
JSONValue import = jsonRoot.Get("CSharpImporter");
return true;
}
示例8: ParseAssemblyJSON
bool CSComponentAssembly::ParseAssemblyJSON(const JSONValue& json)
{
Clear();
assemblyEnums_.Clear();
classNames_.Clear();
const JSONArray& enums = json.Get("enums").GetArray();
// parse to all enums hash
for (unsigned i = 0; i < enums.Size(); i++)
{
const JSONValue& ejson = enums.At(i);
String enumName = ejson.Get("name").GetString();
const JSONObject& evalues = ejson.Get("values").GetObject();
JSONObject::ConstIterator itr = evalues.Begin();
Vector<EnumInfo> values;
while (itr != evalues.End())
{
EnumInfo info;
info.name_ = itr->first_;
info.value_ = itr->second_.GetInt();
values.Push(info);
itr++;
}
assemblyEnums_[enumName] = values;
}
const JSONArray& components = json.Get("components").GetArray();
for (unsigned i = 0; i < components.Size(); i++)
{
const JSONValue& cjson = components.At(i);
ParseComponentClassJSON(cjson);
}
return true;
}
示例9: LoadSettingsInternal
bool NETAssemblyImporter::LoadSettingsInternal(JSONValue& jsonRoot)
{
if (!AssetImporter::LoadSettingsInternal(jsonRoot))
return false;
JSONValue import = jsonRoot.Get("NETAssemblyImporter");
assemblyJSON_.SetType(JSON_NULL);
const JSONValue& ajson = import.Get("AssemblyJSON");
if (ajson.IsObject())
{
assemblyJSON_ = ajson.GetObject();
ResourceCache* cache = GetSubsystem<ResourceCache>();
CSComponentAssembly* assemblyFile = cache->GetResource<CSComponentAssembly>(asset_->GetPath());
if (assemblyFile)
assemblyFile->ParseAssemblyJSON(assemblyJSON_);
}
return true;
}
示例10: Load
// load .asset
bool Asset::Load()
{
FileSystem* fs = GetSubsystem<FileSystem>();
AssetDatabase* db = GetSubsystem<AssetDatabase>();
String assetFilename = GetDotAssetFilename();
SharedPtr<File> file(new File(context_, assetFilename));
json_ = new JSONFile(context_);
json_->Load(*file);
file->Close();
JSONValue root = json_->GetRoot();
assert(root.Get("version").GetInt() == ASSET_VERSION);
guid_ = root.Get("guid").GetString();
db->RegisterGUID(guid_);
dirty_ = false;
if (!CheckCacheFile())
{
LOGINFOF("CheckCacheFile:false - %s", path_.CString());
dirty_ = true;
}
// handle import
if (importer_.NotNull())
importer_->LoadSettings(root);
json_ = 0;
return true;
}
示例11: LoadJSON
bool ObjectAnimation::LoadJSON(const JSONValue& source)
{
attributeAnimationInfos_.Clear();
JSONValue attributeAnimationsValue = source.Get("attributeanimations");
if (attributeAnimationsValue.IsNull())
return true;
if (!attributeAnimationsValue.IsObject())
return true;
const JSONObject& attributeAnimationsObject = attributeAnimationsValue.GetObject();
for (JSONObject::ConstIterator it = attributeAnimationsObject.Begin(); it != attributeAnimationsObject.End(); it++)
{
String name = it->first_;
JSONValue value = it->second_;
SharedPtr<ValueAnimation> animation(new ValueAnimation(context_));
if (!animation->LoadJSON(value))
return false;
String wrapModeString = value.Get("wrapmode").GetString();
WrapMode wrapMode = WM_LOOP;
for (int i = 0; i <= WM_CLAMP; ++i)
{
if (wrapModeString == wrapModeNames[i])
{
wrapMode = (WrapMode)i;
break;
}
}
float speed = value.Get("speed").GetFloat();
AddAttributeAnimation(name, animation, wrapMode, speed);
}
return true;
}
示例12: Load
bool ResourceMapRouter::Load(const JSONValue& json)
{
const JSONValue& assetMap = json.Get("assetMap");
if (!assetMap.IsObject())
return false;
ConstJSONObjectIterator itr = assetMap.Begin();
while (itr != assetMap.End())
{
StringVector tags = itr->first_.Split(';');
if (tags.Size() == 2)
{
resourceMap_[tags[0]][tags[1]] = itr->second_.GetString();
}
itr++;
}
return true;
}
示例13: ParseComponentClassJSON
bool CSComponentAssembly::ParseComponentClassJSON(const JSONValue& json)
{
if (!typeMap_.Size())
InitTypeMap();
String className = json.Get("name").GetString();
classNames_.Push(className);
const JSONValue& jfields = json.Get("fields");
PODVector<StringHash> enumsAdded;
if (jfields.IsArray())
{
for (unsigned i = 0; i < jfields.GetArray().Size(); i++)
{
const JSONValue& jfield = jfields.GetArray().At(i);
VariantType varType = VAR_NONE;
bool isEnum = jfield.Get("isEnum").GetBool();
String typeName = jfield.Get("typeName").GetString();
String fieldName = jfield.Get("name").GetString();
String defaultValue = jfield.Get("defaultValue").GetString();
if (!defaultValue.Length())
{
JSONArray caPos = jfield.Get("caPos").GetArray();
if (caPos.Size())
defaultValue = caPos[0].GetString();
}
if (!defaultValue.Length())
{
JSONObject caNamed = jfield.Get("caNamed").GetObject();
if (caNamed.Contains("DefaultValue"))
defaultValue = caNamed["DefaultValue"].GetString();
}
if (isEnum && assemblyEnums_.Contains(typeName) && !enumsAdded.Contains(fieldName))
{
varType = VAR_INT;
enumsAdded.Push(fieldName);
const Vector<EnumInfo>& einfos = assemblyEnums_[typeName];
for (unsigned i = 0; i < einfos.Size(); i++)
AddEnum(/*typeName*/fieldName, einfos[i], className);
}
if (varType == VAR_NONE && typeMap_.Contains(typeName))
varType = typeMap_[typeName];
if (varType == VAR_NONE)
{
// FIXME: We need to be able to test if a type is a ResourceRef, this isn't really the way to achieve that
const HashMap<StringHash, SharedPtr<ObjectFactory>>& factories = context_->GetObjectFactories();
HashMap<StringHash, SharedPtr<ObjectFactory>>::ConstIterator itr = factories.Begin();
while (itr != factories.End())
{
if (itr->second_->GetTypeName() == typeName)
{
varType = VAR_RESOURCEREF;
break;
}
itr++;
}
if (varType == VAR_NONE)
{
ATOMIC_LOGERRORF("Component Class %s contains unmappable type %s in field %s",
className.CString(), typeName.CString(), fieldName.CString());
continue;
}
}
if (!defaultValue.Length() && varType == VAR_RESOURCEREF)
{
// We still need a default value for ResourceRef's so we know the classtype
AddDefaultValue(fieldName, ResourceRef(typeName), className);
}
else
{
Variant value;
if (varType == VAR_RESOURCEREF)
{
ResourceRef rref(typeName);
rref.name_ = defaultValue;
value = rref;
}
else
{
value.FromString(varType, defaultValue);
}
AddDefaultValue(fieldName, value, className);
//.........这里部分代码省略.........
示例14: Scan
void AssetDatabase::Scan()
{
PruneOrphanedDotAssetFiles();
FileSystem* fs = GetSubsystem<FileSystem>();
const String& resourcePath = project_->GetResourcePath();
Vector<String> allResults;
fs->ScanDir(allResults, resourcePath, "", SCAN_FILES | SCAN_DIRS, true);
Vector<String> filteredResults;
filteredResults.Push(RemoveTrailingSlash(resourcePath));
for (unsigned i = 0; i < allResults.Size(); i++)
{
allResults[i] = resourcePath + allResults[i];
const String& path = allResults[i];
if (path.StartsWith(".") || path.EndsWith("."))
continue;
String ext = GetExtension(path);
if (ext == ".asset")
continue;
filteredResults.Push(path);
}
for (unsigned i = 0; i < filteredResults.Size(); i++)
{
const String& path = filteredResults[i];
String dotAssetFilename = GetDotAssetFilename(path);
if (!fs->FileExists(dotAssetFilename))
{
// new asset
SharedPtr<Asset> asset(new Asset(context_));
if (asset->SetPath(path))
AddAsset(asset);
}
else
{
SharedPtr<File> file(new File(context_, dotAssetFilename));
SharedPtr<JSONFile> json(new JSONFile(context_));
json->Load(*file);
file->Close();
JSONValue root = json->GetRoot();
assert(root.Get("version").GetInt() == ASSET_VERSION);
String guid = root.Get("guid").GetString();
if (!GetAssetByGUID(guid))
{
SharedPtr<Asset> asset(new Asset(context_));
asset->SetPath(path);
AddAsset(asset);
}
}
}
PreloadAssets();
if (ImportDirtyAssets())
Scan();
}
示例15: PreloadResourcesJSON
void Scene::PreloadResourcesJSON(const JSONValue& value)
{
// If not threaded, can not background load resources, so rather load synchronously later when needed
#ifdef URHO3D_THREADING
ResourceCache* cache = GetSubsystem<ResourceCache>();
// Node or Scene attributes do not include any resources; therefore skip to the components
JSONArray componentArray = value.Get("components").GetArray();
for (unsigned i = 0; i < componentArray.Size(); i++)
{
const JSONValue& compValue = componentArray.At(i);
String typeName = compValue.Get("type").GetString();
const Vector<AttributeInfo>* attributes = context_->GetAttributes(StringHash(typeName));
if (attributes)
{
JSONArray attributesArray = compValue.Get("attributes").GetArray();
unsigned startIndex = 0;
for (unsigned j = 0; j < attributesArray.Size(); j++)
{
const JSONValue& attrVal = attributesArray.At(j);
String name = attrVal.Get("name").GetString();
unsigned i = startIndex;
unsigned attempts = attributes->Size();
while (attempts)
{
const AttributeInfo& attr = attributes->At(i);
if ((attr.mode_ & AM_FILE) && !attr.name_.Compare(name, true))
{
if (attr.type_ == VAR_RESOURCEREF)
{
ResourceRef ref = attrVal.Get("value").GetVariantValue(attr.type_).GetResourceRef();
String name = cache->SanitateResourceName(ref.name_);
bool success = cache->BackgroundLoadResource(ref.type_, name);
if (success)
{
++asyncProgress_.totalResources_;
asyncProgress_.resources_.Insert(StringHash(name));
}
}
else if (attr.type_ == VAR_RESOURCEREFLIST)
{
ResourceRefList refList = attrVal.Get("value").GetVariantValue(attr.type_).GetResourceRefList();
for (unsigned k = 0; k < refList.names_.Size(); ++k)
{
String name = cache->SanitateResourceName(refList.names_[k]);
bool success = cache->BackgroundLoadResource(refList.type_, name);
if (success)
{
++asyncProgress_.totalResources_;
asyncProgress_.resources_.Insert(StringHash(name));
}
}
}
startIndex = (i + 1) % attributes->Size();
break;
}
else
{
i = (i + 1) % attributes->Size();
--attempts;
}
}
}
}
}
JSONArray childrenArray = value.Get("children").GetArray();
for (unsigned i = 0; i < childrenArray.Size(); i++)
{
const JSONValue& childVal = childrenArray.At(i);
PreloadResourcesJSON(childVal);
}
#endif
}