本文整理汇总了C++中TSharedRef::GetErrorMessage方法的典型用法代码示例。如果您正苦于以下问题:C++ TSharedRef::GetErrorMessage方法的具体用法?C++ TSharedRef::GetErrorMessage怎么用?C++ TSharedRef::GetErrorMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TSharedRef
的用法示例。
在下文中一共展示了TSharedRef::GetErrorMessage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEXT
TSharedPtr<FJsonObject> UGatherTextCommandletBase::ReadJSONTextFile(const FString& InFilePath)
{
//read in file as string
FString FileContents;
if ( !FFileHelper::LoadFileToString(FileContents, *InFilePath) )
{
UE_LOG(LogGatherTextCommandletBase, Error,TEXT("Failed to load file %s."), *InFilePath);
return NULL;
}
//parse as JSON
TSharedPtr<FJsonObject> JSONObject;
TSharedRef< TJsonReader<> > Reader = TJsonReaderFactory<>::Create( FileContents );
if( !FJsonSerializer::Deserialize( Reader, JSONObject ) || !JSONObject.IsValid())
{
UE_LOG(LogGatherTextCommandletBase, Error,TEXT("Invalid JSON in file %s."), *InFilePath);
UE_LOG(LogGatherTextCommandletBase, Error, TEXT("JSON Error: %s."), *Reader->GetErrorMessage());
return NULL;
}
return JSONObject;
}
示例2: OnReadFileComplete
void FEpicSurvey::OnReadFileComplete( bool bSuccess, const FString& DLName )
{
if ( bSuccess )
{
if ( DLName == SurveyIndexCloudFile.DLName )
{
LoadSurveyIndexFile();
}
else
{
int32 FileHeaderIndex = INDEX_NONE;
TArray< FCloudFileHeader > FileHeaders;
TitleCloud->GetFileList( FileHeaders );
for (int Index = 0; Index < FileHeaders.Num(); Index++)
{
if ( FileHeaders[ Index ].DLName == DLName )
{
FileHeaderIndex = Index;
break;
}
}
if ( FileHeaderIndex > INDEX_NONE )
{
const FCloudFileHeader FileHeader = FileHeaders[ FileHeaderIndex ];
const FString FileExtension = FPaths::GetExtension( FileHeader.FileName );
if ( FileExtension == TEXT("json") )
{
TArray< uint8 > FileContents;
TitleCloud->GetFileContents( DLName, FileContents );
FString SurveyJson;
FFileHelper::BufferToString( SurveyJson, FileContents.GetData(), FileContents.Num() );
TSharedPtr< FJsonObject > SurveyObject = NULL;
TSharedRef< TJsonReader<> > Reader = TJsonReaderFactory<TCHAR>::Create( SurveyJson );
if ( FJsonSerializer::Deserialize( Reader, SurveyObject ) )
{
TSharedPtr< FSurvey > NewSurvey = FSurvey::Create( SharedThis( this ), SurveyObject.ToSharedRef() );
if ( NewSurvey.IsValid() )
{
switch( NewSurvey->GetSurveyType() )
{
case ESurveyType::Normal:
{
auto* Settings = GetDefault<UEditorSettings>();
Surveys.Add( NewSurvey.ToSharedRef() );
const bool IsActiveSurveyInProgress = ActiveSurvey.IsValid() ? Settings->InProgressSurveys.Contains( ActiveSurvey->GetIdentifier() ) : false;
if ( !IsActiveSurveyInProgress )
{
const bool HasBeenCompleted = Settings->CompletedSurveys.Contains( NewSurvey->GetIdentifier() );
if ( !HasBeenCompleted )
{
const bool IsInProgress = Settings->InProgressSurveys.Contains( NewSurvey->GetIdentifier() );
if ( NewSurvey->CanAutoPrompt() )
{
SetActiveSurvey( NewSurvey );
}
else if ( IsInProgress )
{
SetActiveSurvey( NewSurvey );
}
}
}
}
break;
case ESurveyType::Branch:
BranchSurveys.Add( FileHeader.FileName, NewSurvey );
break;
}
}
}
else
{
UE_LOG(LogEpicSurvey, Verbose, TEXT("Parsing JSON survey failed. Filename: %s Message: %s"), *FileHeader.FileName, *Reader->GetErrorMessage());
}
}
else if ( FileExtension == TEXT("png") )
{
TArray< FOnBrushLoaded > MapResults;
FilenameToLoadCallbacks.MultiFind( FileHeaders[ FileHeaderIndex ].FileName, MapResults );
if ( MapResults.Num() > 0 )
{
TArray< uint8 > FileContents;
TitleCloud->GetFileContents( DLName, FileContents );
for (int Index = 0; Index < MapResults.Num(); Index++)
{
MapResults[ Index ].Execute( LoadRawDataAsBrush( *(FString(TEXT("EpicSurvey.")) + FileHeaders[ FileHeaderIndex ].FileName), FileContents ) );
}
FilenameToLoadCallbacks.Remove( FileHeaders[ FileHeaderIndex ].FileName );
}
//.........这里部分代码省略.........
示例3: DeserializeArchiveFromFile
bool FJsonInternationalizationArchiveSerializer::DeserializeArchiveFromFile(const FString& InJsonFile, TSharedRef<FInternationalizationArchive> InArchive, TSharedPtr<const FInternationalizationManifest> InManifest, TSharedPtr<const FInternationalizationArchive> InNativeArchive)
{
// Read in file as string
FString FileContents;
if (!FFileHelper::LoadFileToString(FileContents, *InJsonFile))
{
UE_LOG(LogInternationalizationArchiveSerializer, Error, TEXT("Failed to load archive '%s'."), *InJsonFile);
return false;
}
// Parse as JSON
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(FileContents);
if (!FJsonSerializer::Deserialize(JsonReader, JsonObject) || !JsonObject.IsValid())
{
UE_LOG(LogInternationalizationArchiveSerializer, Error, TEXT("Failed to parse archive '%s'. %s."), *InJsonFile, *JsonReader->GetErrorMessage());
return false;
}
return DeserializeInternal(JsonObject.ToSharedRef(), InArchive, InManifest, InNativeArchive);
}
示例4: ReadTable
bool FDataTableImporterJSON::ReadTable()
{
if (JSONData.IsEmpty())
{
ImportProblems.Add(TEXT("Input data is empty."));
return false;
}
// Check we have a RowStruct specified
if (!DataTable->RowStruct)
{
ImportProblems.Add(TEXT("No RowStruct specified."));
return false;
}
TArray< TSharedPtr<FJsonValue> > ParsedTableRows;
{
const TSharedRef< TJsonReader<TCHAR> > JsonReader = TJsonReaderFactory<TCHAR>::Create(JSONData);
if (!FJsonSerializer::Deserialize(JsonReader, ParsedTableRows) || ParsedTableRows.Num() == 0)
{
ImportProblems.Add(FString::Printf(TEXT("Failed to parse the JSON data. Error: %s"), *JsonReader->GetErrorMessage()));
return false;
}
}
// Empty existing data
DataTable->EmptyTable();
// Iterate over rows
for (int32 RowIdx = 0; RowIdx < ParsedTableRows.Num(); ++RowIdx)
{
const TSharedPtr<FJsonValue>& ParsedTableRowValue = ParsedTableRows[RowIdx];
TSharedPtr<FJsonObject> ParsedTableRowObject = ParsedTableRowValue->AsObject();
if (!ParsedTableRowObject.IsValid())
{
ImportProblems.Add(FString::Printf(TEXT("Row '%d' is not a valid JSON object."), RowIdx));
continue;
}
ReadRow(ParsedTableRowObject.ToSharedRef(), RowIdx);
}
DataTable->Modify(true);
return true;
}
示例5: TEXT
FFeaturePackContentSource::FFeaturePackContentSource(FString InFeaturePackPath, bool bDontRegisterForSearch)
{
FeaturePackPath = InFeaturePackPath;
bPackValid = false;
// Create a pak platform file and mount the feature pack file.
FPakPlatformFile PakPlatformFile;
FString CommandLine;
PakPlatformFile.Initialize(&FPlatformFileManager::Get().GetPlatformFile(), TEXT(""));
FString MountPoint = "root:/";
PakPlatformFile.Mount(*InFeaturePackPath, 0, *MountPoint);
// Gets the manifest file as a JSon string
TArray<uint8> ManifestBuffer;
if( LoadPakFileToBuffer(PakPlatformFile, FPaths::Combine(*MountPoint, TEXT("manifest.json")), ManifestBuffer) == false )
{
RecordAndLogError( FString::Printf(TEXT("Error in Feature pack %s. Cannot find manifest."), *InFeaturePackPath));
Category = EContentSourceCategory::Unknown;
return;
}
FString ManifestString;
FFileHelper::BufferToString(ManifestString, ManifestBuffer.GetData(), ManifestBuffer.Num());
// Populate text fields from the manifest.
TSharedPtr<FJsonObject> ManifestObject;
TSharedRef<TJsonReader<>> ManifestReader = TJsonReaderFactory<>::Create(ManifestString);
FJsonSerializer::Deserialize(ManifestReader, ManifestObject);
if (ManifestReader->GetErrorMessage().IsEmpty() == false)
{
RecordAndLogError( FString::Printf(TEXT("Error in Feature pack %s. Failed to parse manifest: %s"), *InFeaturePackPath, *ManifestReader->GetErrorMessage()));
Category = EContentSourceCategory::Unknown;
return;
}
TSharedPtr<FString> ManifestObjectErrorMessage;
if (TryValidateManifestObject(ManifestObject, ManifestObjectErrorMessage) == false)
{
RecordAndLogError( FString::Printf(TEXT("Error in Feature pack %s. Manifest object error: %s"), *InFeaturePackPath, **ManifestObjectErrorMessage));
Category = EContentSourceCategory::Unknown;
return;
}
for (TSharedPtr<FJsonValue> NameValue : ManifestObject->GetArrayField("Name"))
{
TSharedPtr<FJsonObject> LocalizedNameObject = NameValue->AsObject();
LocalizedNames.Add(FLocalizedText(
LocalizedNameObject->GetStringField("Language"),
FText::FromString(LocalizedNameObject->GetStringField("Text"))));
}
for (TSharedPtr<FJsonValue> DescriptionValue : ManifestObject->GetArrayField("Description"))
{
TSharedPtr<FJsonObject> LocalizedDescriptionObject = DescriptionValue->AsObject();
LocalizedDescriptions.Add(FLocalizedText(
LocalizedDescriptionObject->GetStringField("Language"),
FText::FromString(LocalizedDescriptionObject->GetStringField("Text"))));
}
// Parse asset types field
for (TSharedPtr<FJsonValue> AssetTypesValue : ManifestObject->GetArrayField("AssetTypes"))
{
TSharedPtr<FJsonObject> LocalizedAssetTypesObject = AssetTypesValue->AsObject();
LocalizedAssetTypesList.Add(FLocalizedText(
LocalizedAssetTypesObject->GetStringField("Language"),
FText::FromString(LocalizedAssetTypesObject->GetStringField("Text"))));
}
// Parse asset types field
if( ManifestObject->HasField("SearchTags")==true)
{
for (TSharedPtr<FJsonValue> AssetTypesValue : ManifestObject->GetArrayField("SearchTags"))
{
TSharedPtr<FJsonObject> LocalizedAssetTypesObject = AssetTypesValue->AsObject();
LocalizedSearchTags.Add(FLocalizedTextArray(
LocalizedAssetTypesObject->GetStringField("Language"),
LocalizedAssetTypesObject->GetStringField("Text")));
}
}
// Parse class types field
ClassTypes = ManifestObject->GetStringField("ClassTypes");
// Parse initial focus asset if we have one - this is not required
if (ManifestObject->HasTypedField<EJson::String>("FocusAsset") == true)
{
FocusAssetIdent = ManifestObject->GetStringField("FocusAsset");
}
// Use the path as the sort key - it will be alphabetical that way
SortKey = FeaturePackPath;
ManifestObject->TryGetStringField("SortKey", SortKey);
FString CategoryString = ManifestObject->GetStringField("Category");
UEnum* Enum = FindObjectChecked<UEnum>(ANY_PACKAGE, TEXT("EContentSourceCategory"));
int32 Index = Enum->FindEnumIndex(FName(*CategoryString));
Category = Index != INDEX_NONE ? (EContentSourceCategory)Index : EContentSourceCategory::Unknown;
// Load image data
FString IconFilename = ManifestObject->GetStringField("Thumbnail");
//.........这里部分代码省略.........
示例6: TEXT
TArray<FString> UCurveTable::CreateTableFromJSONString(const FString& InString, ERichCurveInterpMode InterpMode)
{
// Array used to store problems about table creation
TArray<FString> OutProblems;
if (InString.IsEmpty())
{
OutProblems.Add(TEXT("Input data is empty."));
return OutProblems;
}
TArray< TSharedPtr<FJsonValue> > ParsedTableRows;
{
const TSharedRef< TJsonReader<TCHAR> > JsonReader = TJsonReaderFactory<TCHAR>::Create(InString);
if (!FJsonSerializer::Deserialize(JsonReader, ParsedTableRows) || ParsedTableRows.Num() == 0)
{
OutProblems.Add(FString::Printf(TEXT("Failed to parse the JSON data. Error: %s"), *JsonReader->GetErrorMessage()));
return OutProblems;
}
}
// Empty existing data
EmptyTable();
// Iterate over rows
for (int32 RowIdx = 0; RowIdx < ParsedTableRows.Num(); ++RowIdx)
{
const TSharedPtr<FJsonValue>& ParsedTableRowValue = ParsedTableRows[RowIdx];
TSharedPtr<FJsonObject> ParsedTableRowObject = ParsedTableRowValue->AsObject();
if (!ParsedTableRowObject.IsValid())
{
OutProblems.Add(FString::Printf(TEXT("Row '%d' is not a valid JSON object."), RowIdx));
continue;
}
// Get row name
static const FString RowNameJsonKey = TEXT("Name");
const FName RowName = MakeValidName(ParsedTableRowObject->GetStringField(RowNameJsonKey));
// Check its not 'none'
if (RowName == NAME_None)
{
OutProblems.Add(FString::Printf(TEXT("Row '%d' missing a name."), RowIdx));
continue;
}
// Check its not a duplicate
if (RowMap.Find(RowName) != NULL)
{
OutProblems.Add(FString::Printf(TEXT("Duplicate row name '%s'."), *RowName.ToString()));
continue;
}
// Add a key for each entry in this row
FRichCurve* NewCurve = new FRichCurve();
for (const auto& ParsedTableRowEntry : ParsedTableRowObject->Values)
{
// Skip the name entry
if (ParsedTableRowEntry.Key == RowNameJsonKey)
{
continue;
}
// Make sure we have a valid float key
float EntryKey = 0.0f;
if (!LexicalConversion::TryParseString(EntryKey, *ParsedTableRowEntry.Key))
{
OutProblems.Add(FString::Printf(TEXT("Key '%s' on row '%s' is not a float and cannot be parsed."), *ParsedTableRowEntry.Key, *RowName.ToString()));
continue;
}
// Make sure we have a valid float value
double EntryValue = 0.0;
if (!ParsedTableRowEntry.Value->TryGetNumber(EntryValue))
{
OutProblems.Add(FString::Printf(TEXT("Entry '%s' on row '%s' is not a float and cannot be parsed."), *ParsedTableRowEntry.Key, *RowName.ToString()));
continue;
}
FKeyHandle KeyHandle = NewCurve->AddKey(EntryKey, static_cast<float>(EntryValue));
NewCurve->SetKeyInterpMode(KeyHandle, InterpMode);
}
RowMap.Add(RowName, NewCurve);
}
Modify(true);
return OutProblems;
}
示例7: Load
bool FProjectDescriptor::Load(const FString& FileName, FText& OutFailReason)
{
// Read the file to a string
FString FileContents;
if (!FFileHelper::LoadFileToString(FileContents, *FileName))
{
OutFailReason = FText::Format(LOCTEXT("FailedToLoadDescriptorFile", "Failed to open descriptor file '{0}'"), FText::FromString(FileName));
return false;
}
// Deserialize a JSON object from the string
TSharedPtr< FJsonObject > Object;
TSharedRef< TJsonReader<> > Reader = TJsonReaderFactory<>::Create(FileContents);
if ( !FJsonSerializer::Deserialize(Reader, Object) || !Object.IsValid() )
{
OutFailReason = FText::Format(LOCTEXT("FailedToReadDescriptorFile", "Failed to read file. {0}"), FText::FromString(Reader->GetErrorMessage()));
return false;
}
// Parse it as a project descriptor
return Read(*Object.Get(), OutFailReason);
}