My Http response has an array of strings. I was wondering what’s the easiest way to copy those to an TArray<FString>
? The problem is JsonObject->GetArrayField("Teams")
returns an TArray<TSharedPtr<FJsonValue>>
. Now short of looping over every element, I can’t seem to find a simpler way to convert it to a TArray<FString>
.
Not sure what your JSON response looks like - i have the following code workign fine for me - just muscled through this HTTPResponse thing myself today. ObjectField(“Achievements”) is what i would call my array
TSharedPtr<FJsonObject> JsonObj = MakeShareable(new FJsonObject());
FString MsgBody = Response->GetContentAsString();
UE_LOG(LogTemp, Warning, TEXT("%s"), *MsgBody);
TSharedRef<TJsonReader<TCHAR>> Reader = TJsonReaderFactory<TCHAR>::Create(*MsgBody);
if (FJsonSerializer::Deserialize(Reader, JsonObj))
{
TSharedPtr<FJsonObject> AchObj = JsonObj->GetObjectField("Achievements");
UE_LOG(LogTemp, Warning, TEXT("JSON IS VALID"));
// All is okay, json is valid
FString ID = AchObj->GetStringField(TEXT("ID"));
FString TaskType = AchObj->GetStringField(TEXT("TaskType"));
FString ClassID = AchObj->GetStringField(TEXT("ClassID"));
FString Amount_Current = AchObj->GetStringField(TEXT("Amount_Current"));
FString Amount_Needed = AchObj->GetStringField(TEXT("Amount_Needed"));
UE_LOG(LogTemp, Warning, TEXT("%s %s %s %s %s"), *ID, *TaskType, *ClassID, *Amount_Current, *Amount_Needed);
}