Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Get TArray From Http Response

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>.

Product Version: UE 4.17
more ▼

asked Sep 30 '17 at 09:48 PM in C++ Programming

avatar image

492 67 65 212

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

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);
more ▼

answered Oct 04 '17 at 09:03 AM

avatar image

117 9 14 24

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question