本文整理汇总了C++中TSharedPtr::AsObject方法的典型用法代码示例。如果您正苦于以下问题:C++ TSharedPtr::AsObject方法的具体用法?C++ TSharedPtr::AsObject怎么用?C++ TSharedPtr::AsObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TSharedPtr
的用法示例。
在下文中一共展示了TSharedPtr::AsObject方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SaveGestures
void FUserDefinedGestures::SaveGestures() const
{
if( Gestures.IsValid() )
{
FString GestureRawJsonContent;
TArray<FString> GestureJsonArray;
for(const auto& GestureInfo : *Gestures)
{
TSharedPtr<FJsonValueObject> GestureInfoValueObj = MakeShareable( new FJsonValueObject( MakeShareable( new FJsonObject ) ) );
TSharedPtr<FJsonObject> GestureInfoObj = GestureInfoValueObj->AsObject();
// Set the gesture values for the command
GestureInfoObj->Values.Add( TEXT("BindingContext"), MakeShareable( new FJsonValueString( GestureInfo.Key.BindingContext.ToString() ) ) );
GestureInfoObj->Values.Add( TEXT("CommandName"), MakeShareable( new FJsonValueString( GestureInfo.Key.CommandName.ToString() ) ) );
GestureInfoObj->Values.Add( TEXT("Control"), MakeShareable( new FJsonValueBoolean( GestureInfo.Value.NeedsControl() ) ) );
GestureInfoObj->Values.Add( TEXT("Alt"), MakeShareable( new FJsonValueBoolean( GestureInfo.Value.NeedsAlt() ) ) );
GestureInfoObj->Values.Add( TEXT("Shift"), MakeShareable( new FJsonValueBoolean( GestureInfo.Value.NeedsShift() ) ) );
GestureInfoObj->Values.Add( TEXT("Command"), MakeShareable( new FJsonValueBoolean( GestureInfo.Value.NeedsCommand() ) ) );
GestureInfoObj->Values.Add( TEXT("Key"), MakeShareable( new FJsonValueString( GestureInfo.Value.Key.ToString() ) ) );
auto JsonWriter = TJsonWriterFactory< TCHAR, TCondensedJsonPrintPolicy<TCHAR> >::Create( &GestureRawJsonContent );
FJsonSerializer::Serialize( GestureInfoObj.ToSharedRef(), JsonWriter );
const FString EscapedContent = FRemoteConfig::ReplaceIniCharWithSpecialChar(GestureRawJsonContent).ReplaceCharWithEscapedChar();
GestureJsonArray.Add(EscapedContent);
}
GConfig->SetArray(TEXT("UserDefinedGestures"), TEXT("UserDefinedGestures"), GestureJsonArray, GEditorKeyBindingsIni);
// Clean up the old Content key (if it still exists)
GConfig->RemoveKey(TEXT("UserDefinedGestures"), TEXT("Content"), GEditorKeyBindingsIni);
}
}
示例2: ParseFramesFromSpriteHash
static bool ParseFramesFromSpriteHash(TSharedPtr<FJsonObject> ObjectBlock, TArray<FSpriteFrame>& OutSpriteFrames, TSet<FName>& FrameNames)
{
GWarn->BeginSlowTask(NSLOCTEXT("Paper2D", "PaperJsonImporterFactory_ParsingSprites", "Parsing Sprite Frame"), true, true);
bool bLoadedSuccessfully = true;
// Parse all of the frames
int32 FrameCount = 0;
for (auto FrameIt = ObjectBlock->Values.CreateIterator(); FrameIt; ++FrameIt)
{
GWarn->StatusUpdate(FrameCount, ObjectBlock->Values.Num(), NSLOCTEXT("Paper2D", "PaperJsonImporterFactory_ParsingSprites", "Parsing Sprite Frames"));
bool bReadFrameSuccessfully = true;
FSpriteFrame Frame;
Frame.FrameName = *FrameIt.Key();
if (FrameNames.Contains(Frame.FrameName))
{
bReadFrameSuccessfully = false;
}
else
{
FrameNames.Add(Frame.FrameName);
}
TSharedPtr<FJsonValue> FrameDataAsValue = FrameIt.Value();
TSharedPtr<FJsonObject> FrameData;
if (FrameDataAsValue->Type == EJson::Object)
{
FrameData = FrameDataAsValue->AsObject();
bReadFrameSuccessfully = bReadFrameSuccessfully && ParseFrame(FrameData, /*out*/Frame);
}
else
{
bReadFrameSuccessfully = false;
}
if (bReadFrameSuccessfully)
{
OutSpriteFrames.Add(Frame);
}
else
{
UE_LOG(LogPaperSpriteSheetImporter, Warning, TEXT("Frame %s is in an unexpected format"), *Frame.FrameName.ToString());
bLoadedSuccessfully = false;
}
FrameCount++;
}
GWarn->EndSlowTask();
return bLoadedSuccessfully;
}
示例3: SetArrayField
void UVaRestJsonObject::SetArrayField(const FString& FieldName, const TArray<UVaRestJsonValue*>& InArray)
{
if (!JsonObj.IsValid())
{
return;
}
TArray< TSharedPtr<FJsonValue> > ValArray;
// Process input array and COPY original values
for (auto InVal : InArray)
{
TSharedPtr<FJsonValue> JsonVal = InVal->GetRootValue();
switch (InVal->GetType())
{
case EVaJson::None:
break;
case EVaJson::Null:
ValArray.Add(MakeShareable(new FJsonValueNull()));
break;
case EVaJson::String:
ValArray.Add(MakeShareable(new FJsonValueString(JsonVal->AsString())));
break;
case EVaJson::Number:
ValArray.Add(MakeShareable(new FJsonValueNumber(JsonVal->AsNumber())));
break;
case EVaJson::Boolean:
ValArray.Add(MakeShareable(new FJsonValueBoolean(JsonVal->AsBool())));
break;
case EVaJson::Array:
ValArray.Add(MakeShareable(new FJsonValueArray(JsonVal->AsArray())));
break;
case EVaJson::Object:
ValArray.Add(MakeShareable(new FJsonValueObject(JsonVal->AsObject())));
break;
default:
break;
}
}
JsonObj->SetArrayField(FieldName, ValArray);
}
示例4: CopyJsonValueToWriter
void CopyJsonValueToWriter( JsonWriter &Json, const FString& ValueName, const TSharedPtr<FJsonValue>& JsonValue )
{
if ( JsonValue->Type == EJson::String )
{
Json->WriteValue( ValueName, JsonValue->AsString() );
}
else if ( JsonValue->Type == EJson::Array )
{
if (ValueName.IsEmpty())
{
Json->WriteArrayStart();
}
else
{
Json->WriteArrayStart(ValueName);
}
const TArray<TSharedPtr<FJsonValue>>& Array = JsonValue->AsArray();
for ( const auto& ArrayValue : Array )
{
CopyJsonValueToWriter(Json, FString(), ArrayValue);
}
Json->WriteArrayEnd();
}
else if ( JsonValue->Type == EJson::Object )
{
if (ValueName.IsEmpty())
{
Json->WriteObjectStart();
}
else
{
Json->WriteObjectStart(ValueName);
}
const TSharedPtr<FJsonObject>& Object = JsonValue->AsObject();
for ( const auto& ObjectProperty : Object->Values)
{
CopyJsonValueToWriter(Json, ObjectProperty.Key, ObjectProperty.Value );
}
Json->WriteObjectEnd();
}
else
{
UE_LOG(LogChunkManifestGenerator, Warning, TEXT("Unrecognized json value type %d in object %s"), *UEnum::GetValueAsString(TEXT("Json.EJson"), JsonValue->Type), *ValueName)
}
}
示例5: DeserializeFromJSON
// @TODO LSwift: Perhaps replace FromBlob and ToBlob usage with hexadecimal notation instead
bool FBuildPatchAppManifest::DeserializeFromJSON( const FString& JSONInput )
{
bool bSuccess = true;
TSharedPtr<FJsonObject> JSONManifestObject;
TSharedRef<TJsonReader<TCHAR>> Reader = TJsonReaderFactory<TCHAR>::Create(JSONInput);
// Clear current data
DestroyData();
// Attempt to deserialize JSON
if (!FJsonSerializer::Deserialize(Reader, JSONManifestObject) || !JSONManifestObject.IsValid())
{
return false;
}
// Store a list of all data GUID for later use
TSet<FGuid> AllDataGuids;
// Get the values map
TMap<FString, TSharedPtr<FJsonValue>>& JsonValueMap = JSONManifestObject->Values;
// Manifest version did not always exist
int32 ManifestFileVersionInt = 0;
TSharedPtr<FJsonValue> JsonManifestFileVersion = JsonValueMap.FindRef(TEXT("ManifestFileVersion"));
if (JsonManifestFileVersion.IsValid() && FromStringBlob(JsonManifestFileVersion->AsString(), ManifestFileVersionInt))
{
Data->ManifestFileVersion = static_cast<EBuildPatchAppManifestVersion::Type>(ManifestFileVersionInt);
}
else
{
// Then we presume version just before we started outputting the version
Data->ManifestFileVersion = static_cast<EBuildPatchAppManifestVersion::Type>(EBuildPatchAppManifestVersion::StartStoringVersion - 1);
}
// Get the app and version strings
TSharedPtr< FJsonValue > JsonAppID = JsonValueMap.FindRef( TEXT("AppID") );
TSharedPtr< FJsonValue > JsonAppNameString = JsonValueMap.FindRef( TEXT("AppNameString") );
TSharedPtr< FJsonValue > JsonBuildVersionString = JsonValueMap.FindRef( TEXT("BuildVersionString") );
TSharedPtr< FJsonValue > JsonLaunchExe = JsonValueMap.FindRef( TEXT("LaunchExeString") );
TSharedPtr< FJsonValue > JsonLaunchCommand = JsonValueMap.FindRef( TEXT("LaunchCommand") );
TSharedPtr< FJsonValue > JsonPrereqName = JsonValueMap.FindRef( TEXT("PrereqName") );
TSharedPtr< FJsonValue > JsonPrereqPath = JsonValueMap.FindRef( TEXT("PrereqPath") );
TSharedPtr< FJsonValue > JsonPrereqArgs = JsonValueMap.FindRef( TEXT("PrereqArgs") );
bSuccess = bSuccess && JsonAppID.IsValid();
if( bSuccess )
{
bSuccess = bSuccess && FromStringBlob( JsonAppID->AsString(), Data->AppID );
}
bSuccess = bSuccess && JsonAppNameString.IsValid();
if( bSuccess )
{
Data->AppName = JsonAppNameString->AsString();
}
bSuccess = bSuccess && JsonBuildVersionString.IsValid();
if( bSuccess )
{
Data->BuildVersion = JsonBuildVersionString->AsString();
}
bSuccess = bSuccess && JsonLaunchExe.IsValid();
if( bSuccess )
{
Data->LaunchExe = JsonLaunchExe->AsString();
}
bSuccess = bSuccess && JsonLaunchCommand.IsValid();
if( bSuccess )
{
Data->LaunchCommand = JsonLaunchCommand->AsString();
}
// Get the prerequisites installer info. These are optional entries.
Data->PrereqName = JsonPrereqName.IsValid() ? JsonPrereqName->AsString() : FString();
Data->PrereqPath = JsonPrereqPath.IsValid() ? JsonPrereqPath->AsString() : FString();
Data->PrereqArgs = JsonPrereqArgs.IsValid() ? JsonPrereqArgs->AsString() : FString();
// Get the FileManifestList
TSharedPtr<FJsonValue> JsonFileManifestList = JsonValueMap.FindRef(TEXT("FileManifestList"));
bSuccess = bSuccess && JsonFileManifestList.IsValid();
if( bSuccess )
{
TArray<TSharedPtr<FJsonValue>> JsonFileManifestArray = JsonFileManifestList->AsArray();
for (auto JsonFileManifestIt = JsonFileManifestArray.CreateConstIterator(); JsonFileManifestIt && bSuccess; ++JsonFileManifestIt)
{
TSharedPtr<FJsonObject> JsonFileManifest = (*JsonFileManifestIt)->AsObject();
const int32 FileIndex = Data->FileManifestList.Add(FFileManifestData());
FFileManifestData& FileManifest = Data->FileManifestList[FileIndex];
FileManifest.Filename = JsonFileManifest->GetStringField(TEXT("Filename"));
bSuccess = bSuccess && FString::ToBlob(JsonFileManifest->GetStringField(TEXT("FileHash")), FileManifest.FileHash.Hash, FSHA1::DigestSize);
TArray<TSharedPtr<FJsonValue>> JsonChunkPartArray = JsonFileManifest->GetArrayField(TEXT("FileChunkParts"));
for (auto JsonChunkPartIt = JsonChunkPartArray.CreateConstIterator(); JsonChunkPartIt && bSuccess; ++JsonChunkPartIt)
{
const int32 ChunkIndex = FileManifest.FileChunkParts.Add(FChunkPartData());
FChunkPartData& FileChunkPart = FileManifest.FileChunkParts[ChunkIndex];
TSharedPtr<FJsonObject> JsonChunkPart = (*JsonChunkPartIt)->AsObject();
bSuccess = bSuccess && FGuid::Parse(JsonChunkPart->GetStringField(TEXT("Guid")), FileChunkPart.Guid);
bSuccess = bSuccess && FromStringBlob(JsonChunkPart->GetStringField(TEXT("Offset")), FileChunkPart.Offset);
bSuccess = bSuccess && FromStringBlob(JsonChunkPart->GetStringField(TEXT("Size")), FileChunkPart.Size);
AllDataGuids.Add(FileChunkPart.Guid);
}
//.........这里部分代码省略.........
示例6: TEXT
bool PlayFab::MatchmakerModels::FUserInfoResponse::readFromValue(const TSharedPtr<FJsonObject>& obj)
{
bool HasSucceeded = true;
const TSharedPtr<FJsonValue> PlayFabIdValue = obj->TryGetField(TEXT("PlayFabId"));
if (PlayFabIdValue.IsValid()&& !PlayFabIdValue->IsNull())
{
FString TmpValue;
if(PlayFabIdValue->TryGetString(TmpValue)) {PlayFabId = TmpValue; }
}
const TSharedPtr<FJsonValue> UsernameValue = obj->TryGetField(TEXT("Username"));
if (UsernameValue.IsValid()&& !UsernameValue->IsNull())
{
FString TmpValue;
if(UsernameValue->TryGetString(TmpValue)) {Username = TmpValue; }
}
const TSharedPtr<FJsonValue> TitleDisplayNameValue = obj->TryGetField(TEXT("TitleDisplayName"));
if (TitleDisplayNameValue.IsValid()&& !TitleDisplayNameValue->IsNull())
{
FString TmpValue;
if(TitleDisplayNameValue->TryGetString(TmpValue)) {TitleDisplayName = TmpValue; }
}
{
const TArray< TSharedPtr<FJsonValue> >&InventoryArray = FPlayFabJsonHelpers::ReadArray(obj, TEXT("Inventory"));
for (int32 Idx = 0; Idx < InventoryArray.Num(); Idx++)
{
TSharedPtr<FJsonValue> CurrentItem = InventoryArray[Idx];
Inventory.Add(FItemInstance(CurrentItem->AsObject()));
}
}
const TSharedPtr<FJsonObject>* VirtualCurrencyObject;
if (obj->TryGetObjectField(TEXT("VirtualCurrency"), VirtualCurrencyObject))
{
for (TMap<FString, TSharedPtr<FJsonValue>>::TConstIterator It((*VirtualCurrencyObject)->Values); It; ++It)
{
int32 TmpValue; It.Value()->TryGetNumber(TmpValue);
VirtualCurrency.Add(It.Key(), TmpValue);
}
}
const TSharedPtr<FJsonObject>* VirtualCurrencyRechargeTimesObject;
if (obj->TryGetObjectField(TEXT("VirtualCurrencyRechargeTimes"), VirtualCurrencyRechargeTimesObject))
{
for (TMap<FString, TSharedPtr<FJsonValue>>::TConstIterator It((*VirtualCurrencyRechargeTimesObject)->Values); It; ++It)
{
VirtualCurrencyRechargeTimes.Add(It.Key(), FVirtualCurrencyRechargeTime(It.Value()->AsObject()));
}
}
const TSharedPtr<FJsonValue> IsDeveloperValue = obj->TryGetField(TEXT("IsDeveloper"));
if (IsDeveloperValue.IsValid()&& !IsDeveloperValue->IsNull())
{
bool TmpValue;
if(IsDeveloperValue->TryGetBool(TmpValue)) {IsDeveloper = TmpValue; }
}
const TSharedPtr<FJsonValue> SteamIdValue = obj->TryGetField(TEXT("SteamId"));
if (SteamIdValue.IsValid()&& !SteamIdValue->IsNull())
{
FString TmpValue;
if(SteamIdValue->TryGetString(TmpValue)) {SteamId = TmpValue; }
}
return HasSucceeded;
}
示例7: JsonObjToArchive
bool FJsonInternationalizationArchiveSerializer::JsonObjToArchive(TSharedRef<FJsonObject> InJsonObj, const FString& ParentNamespace, TSharedRef<FInternationalizationArchive> InArchive, TSharedPtr<const FInternationalizationManifest> InManifest, TSharedPtr<const FInternationalizationArchive> InNativeArchive)
{
bool bConvertSuccess = true;
FString AccumulatedNamespace = ParentNamespace;
if (InJsonObj->HasField(TAG_NAMESPACE))
{
if (!(AccumulatedNamespace.IsEmpty()))
{
AccumulatedNamespace += NAMESPACE_DELIMITER;
}
AccumulatedNamespace += InJsonObj->GetStringField(TAG_NAMESPACE);
}
else
{
UE_LOG(LogInternationalizationArchiveSerializer, Warning, TEXT("Encountered an object with a missing namespace while converting to Internationalization archive."));
bConvertSuccess = false;
}
// Process all the child objects
if (bConvertSuccess && InJsonObj->HasField(TAG_CHILDREN))
{
const TArray< TSharedPtr<FJsonValue> > ChildrenArray = InJsonObj->GetArrayField(TAG_CHILDREN);
for (TArray< TSharedPtr< FJsonValue > >::TConstIterator ChildIter(ChildrenArray.CreateConstIterator()); ChildIter; ++ChildIter)
{
const TSharedPtr< FJsonValue > ChildEntry = *ChildIter;
const TSharedPtr< FJsonObject > ChildJSONObject = ChildEntry->AsObject();
FString SourceText;
TSharedPtr< FLocMetadataObject > SourceMetadata;
if (ChildJSONObject->HasTypedField< EJson::String >(TAG_DEPRECATED_DEFAULTTEXT))
{
SourceText = ChildJSONObject->GetStringField(TAG_DEPRECATED_DEFAULTTEXT);
}
else if (ChildJSONObject->HasTypedField< EJson::Object >(TAG_SOURCE))
{
const TSharedPtr< FJsonObject > SourceJSONObject = ChildJSONObject->GetObjectField(TAG_SOURCE);
if (SourceJSONObject->HasTypedField< EJson::String >(TAG_SOURCE_TEXT))
{
SourceText = SourceJSONObject->GetStringField(TAG_SOURCE_TEXT);
// Source meta data is mixed in with the source text, we'll process metadata if the source json object has more than one entry
if (SourceJSONObject->Values.Num() > 1)
{
// We load in the entire source object as metadata and just remove the source text.
FJsonInternationalizationMetaDataSerializer::DeserializeMetadata(SourceJSONObject.ToSharedRef(), SourceMetadata);
if (SourceMetadata.IsValid())
{
SourceMetadata->Values.Remove(TAG_SOURCE_TEXT);
}
}
}
else
{
bConvertSuccess = false;
}
}
else
{
bConvertSuccess = false;
}
FString TranslationText;
TSharedPtr< FLocMetadataObject > TranslationMetadata;
if (ChildJSONObject->HasTypedField< EJson::String >(TAG_DEPRECATED_TRANSLATEDTEXT))
{
TranslationText = ChildJSONObject->GetStringField(TAG_DEPRECATED_TRANSLATEDTEXT);
}
else if (ChildJSONObject->HasTypedField< EJson::Object >(TAG_TRANSLATION))
{
const TSharedPtr< FJsonObject > TranslationJSONObject = ChildJSONObject->GetObjectField(TAG_TRANSLATION);
if (TranslationJSONObject->HasTypedField< EJson::String >(TAG_TRANSLATION_TEXT))
{
TranslationText = TranslationJSONObject->GetStringField(TAG_TRANSLATION_TEXT);
// Source meta data is mixed in with the source text, we'll process metadata if the source json object has more than one entry
if (TranslationJSONObject->Values.Num() > 1)
{
// We load in the entire source object as metadata and remove the source text
FJsonInternationalizationMetaDataSerializer::DeserializeMetadata(TranslationJSONObject.ToSharedRef(), TranslationMetadata);
if (TranslationJSONObject.IsValid())
{
TranslationJSONObject->Values.Remove(TAG_TRANSLATION_TEXT);
}
}
}
else
{
bConvertSuccess = false;
}
}
else
{
bConvertSuccess = false;
}
if (bConvertSuccess)
{
FLocItem Source(SourceText);
//.........这里部分代码省略.........
示例8: JsonObjToManifest
bool FInternationalizationManifestJsonSerializer::JsonObjToManifest( TSharedRef< FJsonObject > InJsonObj, FString ParentNamespace, TSharedRef< FInternationalizationManifest > Manifest )
{
bool bConvertSuccess = true;
FString AccumulatedNamespace = ParentNamespace;
if( InJsonObj->HasField( TAG_NAMESPACE) )
{
if( !( AccumulatedNamespace.IsEmpty() ) )
{
AccumulatedNamespace += NAMESPACE_DELIMITER;
}
AccumulatedNamespace += InJsonObj->GetStringField( TAG_NAMESPACE );
}
else
{
// We found an entry with a missing namespace
bConvertSuccess = false;
}
// Process all the child objects
if( bConvertSuccess && InJsonObj->HasField( TAG_CHILDREN ) )
{
const TArray< TSharedPtr< FJsonValue> > ChildrenArray = InJsonObj->GetArrayField( TAG_CHILDREN );
for(TArray< TSharedPtr< FJsonValue > >::TConstIterator ChildIter( ChildrenArray.CreateConstIterator() ); ChildIter && bConvertSuccess; ++ChildIter)
{
const TSharedPtr< FJsonValue > ChildEntry = *ChildIter;
const TSharedPtr< FJsonObject > ChildJSONObject = ChildEntry->AsObject();
FString SourceText;
TSharedPtr< FLocMetadataObject > SourceMetadata;
if( ChildJSONObject->HasTypedField< EJson::String>( TAG_DEPRECATED_DEFAULTTEXT) )
{
SourceText = ChildJSONObject->GetStringField( TAG_DEPRECATED_DEFAULTTEXT );
}
else if( ChildJSONObject->HasTypedField< EJson::Object>( TAG_SOURCE ) )
{
const TSharedPtr< FJsonObject > SourceJSONObject = ChildJSONObject->GetObjectField( TAG_SOURCE );
if( SourceJSONObject->HasTypedField< EJson::String >( TAG_SOURCE_TEXT ) )
{
SourceText = SourceJSONObject->GetStringField( TAG_SOURCE_TEXT );
// Source meta data is mixed in with the source text, we'll process metadata if the source json object has more than one entry
if( SourceJSONObject->Values.Num() > 1 )
{
// We load in the entire source object as metadata and remove the source object
FInternationalizationMetaDataJsonSerializer::DeserializeMetadata( SourceJSONObject.ToSharedRef(), SourceMetadata );
if( SourceMetadata.IsValid() )
{
SourceMetadata->Values.Remove( TAG_SOURCE_TEXT );
}
}
}
else
{
bConvertSuccess = false;
}
}
else
{
bConvertSuccess = false;
}
FLocItem Source(SourceText);
Source.MetadataObj = SourceMetadata;
if( bConvertSuccess && ChildJSONObject->HasField( TAG_KEYCOLLECTION ) )
{
const TArray< TSharedPtr<FJsonValue> > ContextArray = ChildJSONObject->GetArrayField( TAG_KEYCOLLECTION);
for(TArray< TSharedPtr< FJsonValue > >::TConstIterator ContextIter( ContextArray.CreateConstIterator() ); ContextIter && bConvertSuccess; ++ContextIter)
{
const TSharedPtr< FJsonValue > ContextEntry = *ContextIter;
const TSharedPtr< FJsonObject > ContextJSONObject = ContextEntry->AsObject();
if( ContextJSONObject->HasTypedField< EJson::String >( TAG_KEY ) )
{
const FString Key = ContextJSONObject->GetStringField( TAG_KEY );
const FString SourceLocation = ContextJSONObject->HasField( TAG_PATH ) ? ContextJSONObject->GetStringField( TAG_PATH ) : FString();
FContext CommandContext;
CommandContext.Key = Key;
CommandContext.SourceLocation = SourceLocation;
if( ContextJSONObject->HasTypedField< EJson::Boolean >( TAG_OPTIONAL ) )
{
CommandContext.bIsOptional = ContextJSONObject->GetBoolField( TAG_OPTIONAL );
}
if( ContextJSONObject->HasTypedField< EJson::Object >( TAG_METADATA ) )
{
const TSharedPtr< FJsonObject > MetaDataJSONObject = ContextJSONObject->GetObjectField( TAG_METADATA );
if( MetaDataJSONObject->HasTypedField< EJson::Object >( TAG_METADATA_INFO ) )
{
const TSharedPtr< FJsonObject > MetaDataInfoJSONObject = MetaDataJSONObject->GetObjectField( TAG_METADATA_INFO );
TSharedPtr< FLocMetadataObject > MetadataNode;
FInternationalizationMetaDataJsonSerializer::DeserializeMetadata( MetaDataInfoJSONObject.ToSharedRef(), MetadataNode );
//.........这里部分代码省略.........
示例9: JsonObjToArchive
bool FInternationalizationArchiveJsonSerializer::JsonObjToArchive( TSharedRef< FJsonObject > InJsonObj, FString ParentNamespace, TSharedRef< FInternationalizationArchive > InternationalizationArchive )
{
bool bConvertSuccess = true;
FString AccumulatedNamespace = ParentNamespace;
if( InJsonObj->HasField( TAG_NAMESPACE) )
{
if( !( AccumulatedNamespace.IsEmpty() ) )
{
AccumulatedNamespace += NAMESPACE_DELIMITER;
}
AccumulatedNamespace += InJsonObj->GetStringField( TAG_NAMESPACE );
}
else
{
UE_LOG( LogInternationalizationArchiveSerializer, Warning,TEXT("Encountered an object with a missing namespace while converting to Internationalization archive.") );
bConvertSuccess = false;
}
// Process all the child objects
if( bConvertSuccess && InJsonObj->HasField( TAG_CHILDREN ) )
{
const TArray< TSharedPtr<FJsonValue> > ChildrenArray = InJsonObj->GetArrayField( TAG_CHILDREN );
for( TArray< TSharedPtr< FJsonValue > >::TConstIterator ChildIter( ChildrenArray.CreateConstIterator() ); ChildIter; ++ChildIter )
{
const TSharedPtr< FJsonValue > ChildEntry = *ChildIter;
const TSharedPtr< FJsonObject > ChildJSONObject = ChildEntry->AsObject();
FString SourceText;
TSharedPtr< FLocMetadataObject > SourceMetadata;
if( ChildJSONObject->HasTypedField< EJson::String >( TAG_DEPRECATED_DEFAULTTEXT ) )
{
SourceText = ChildJSONObject->GetStringField( TAG_DEPRECATED_DEFAULTTEXT );
}
else if( ChildJSONObject->HasTypedField< EJson::Object >( TAG_SOURCE ) )
{
const TSharedPtr< FJsonObject > SourceJSONObject = ChildJSONObject->GetObjectField( TAG_SOURCE );
if( SourceJSONObject->HasTypedField< EJson::String >( TAG_SOURCE_TEXT ) )
{
SourceText = SourceJSONObject->GetStringField( TAG_SOURCE_TEXT );
// Source meta data is mixed in with the source text, we'll process metadata if the source json object has more than one entry
if( SourceJSONObject->Values.Num() > 1 )
{
// We load in the entire source object as metadata and just remove the source text.
FInternationalizationMetaDataJsonSerializer::DeserializeMetadata( SourceJSONObject.ToSharedRef(), SourceMetadata );
if( SourceMetadata.IsValid() )
{
SourceMetadata->Values.Remove( TAG_SOURCE_TEXT );
}
}
}
else
{
bConvertSuccess = false;
}
}
else
{
bConvertSuccess = false;
}
FString TranslationText;
TSharedPtr< FLocMetadataObject > TranslationMetadata;
if( ChildJSONObject->HasTypedField< EJson::String >( TAG_DEPRECATED_TRANSLATEDTEXT ) )
{
TranslationText = ChildJSONObject->GetStringField( TAG_DEPRECATED_TRANSLATEDTEXT );
}
else if( ChildJSONObject->HasTypedField< EJson::Object >( TAG_TRANSLATION ) )
{
const TSharedPtr< FJsonObject > TranslationJSONObject = ChildJSONObject->GetObjectField( TAG_TRANSLATION );
if( TranslationJSONObject->HasTypedField< EJson::String >( TAG_TRANSLATION_TEXT ) )
{
TranslationText = TranslationJSONObject->GetStringField( TAG_TRANSLATION_TEXT );
// Source meta data is mixed in with the source text, we'll process metadata if the source json object has more than one entry
if( TranslationJSONObject->Values.Num() > 1 )
{
// We load in the entire source object as metadata and remove the source text
FInternationalizationMetaDataJsonSerializer::DeserializeMetadata( TranslationJSONObject.ToSharedRef(), TranslationMetadata );
if( TranslationJSONObject.IsValid() )
{
TranslationJSONObject->Values.Remove( TAG_TRANSLATION_TEXT );
}
}
}
else
{
bConvertSuccess = false;
}
}
else
{
bConvertSuccess = false;
}
if( bConvertSuccess )
{
FLocItem Source( SourceText );
//.........这里部分代码省略.........
示例10: ParsePlot
FPlot ParsePlot(int32 nPlotID)
{
FString sValue;
FString sPlot = FString::FromInt(nPlotID);
FString aFullPath = FPaths::GameDevelopersDir();
aFullPath += "Source/JSON/PLO/";
aFullPath += *sPlot;
aFullPath += ".json";
FString JsonStr;
FFileHelper::LoadFileToString(JsonStr, *aFullPath);
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonStr);
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
FPlot plot;
if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
{
plot.ResRefID = nPlotID;
TMap<FString, TSharedPtr<FJsonValue>> JsonValuesMap = JsonObject->Values;
TSharedPtr<FJsonValue> rootValues;
JsonValuesMap.RemoveAndCopyValue("Resource", rootValues);
TSharedPtr<FJsonObject> rootObject = rootValues->AsObject();
TMap<FString, TSharedPtr<FJsonValue>> rootValuesMap = rootObject->Values;
TSharedPtr<FJsonValue> agentValues;
rootValuesMap.RemoveAndCopyValue("Agent", agentValues);
TSharedPtr<FJsonObject> agentObject = agentValues->AsObject();
TMap<FString, TSharedPtr<FJsonValue>> agentValuesMap = agentObject->Values;
for (auto const& y : agentValuesMap)
{
if (y.Key == "ResRefName")
{
y.Value.Get()->TryGetString(sValue);
plot.ResRefName = sValue;
}
if (y.Key == "LocalCopy")
{
y.Value.Get()->TryGetString(sValue);
plot.LocalCopy = sValue == "False" ? false : true;
}
if (y.Key == "Name")
{
y.Value.Get()->TryGetString(sValue);
plot.Name = sValue;
}
if (y.Key == "NameStringID")
{
y.Value.Get()->TryGetString(sValue);
plot.NameStringID = FCString::Atoi(*sValue);
}
if (y.Key == "NameRequiresReTranslation")
{
y.Value.Get()->TryGetString(sValue);
plot.NameRequiresReTranslation = sValue == "False" ? false : true;
}
if (y.Key == "GUID")
{
y.Value.Get()->TryGetString(sValue);
plot.GUID = sValue;
}
if (y.Key == "ScriptURI")
{
y.Value.Get()->TryGetString(sValue);
plot.ScriptURI = FCString::Atoi(*sValue);
}
if (y.Key == "Priority")
{
y.Value.Get()->TryGetString(sValue);
plot.Priority = FCString::Atoi(*sValue);
}
if (y.Key == "JournalImage")
{
y.Value.Get()->TryGetString(sValue);
plot.JournalImage = sValue;
}
if (y.Key == "ParentPlotURI")
{
y.Value.Get()->TryGetString(sValue);
plot.ParentPlotURI = FCString::Atoi(*sValue);
}
if (y.Key == "EntryType")
{
y.Value.Get()->TryGetString(sValue);
plot.EntryType = FCString::Atoi(*sValue);
}
if (y.Key == "AllowPausing")
{
y.Value.Get()->TryGetString(sValue);
plot.AllowPausing = sValue == "False" ? false : true;
}
}
TSharedPtr<FJsonValue> StatusListValues;
agentValuesMap.RemoveAndCopyValue("StatusList", StatusListValues);
//.........这里部分代码省略.........