Accessing array of object after deserialization

Hi,

I’m new to UE4. I’m trying HTTP GET request in using c++ code.
I’m able to fetch the response but unable to access array of object after deserializing it.

Here is my response obtained from get request

 {
"person": [{
	"first_name": "Paul",
	"referal_code": "PP006",
	"last_name": "James"
}, {
	"first_name": "Admans",
	"referal_code": "PP014",
	"last_name": "Peter"
}]
}

Here is my code snippet

<-------------HTTPActor.h file------------------------->

#pragma once
#include "GameFramework/Actor.h"
#include "Runtime/Online/HTTP/Public/Http.h"
#include "HTTPActor.generated.h"

USTRUCT()
struct FPersonInfo
{
GENERATED_USTRUCT_BODY()

	UPROPERTY()
	FString first_name;

UPROPERTY()
	FString referal_code;

UPROPERTY()
	FString last_name;
};


UCLASS()
class 3D_API AHTTPActor : public AActor
{
GENERATED_BODY()

public:
FHttpModule* Http;
/* The actual HTTP call */
UFUNCTION()
	void MyHttpCall();

/*Assign this function to call when the GET request processes sucessfully*/
void OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);

// Sets default values for this actor's properties
AHTTPActor();

// Called when the game starts or when spawned
virtual void BeginPlay() override;
};

<-------------HTTPActor.cpp file------------------------->

#include "3D.h"
#include "HTTPActor.h"
#include <array>
#include <string>

// Sets default values
AHTTPActor::AHTTPActor()
{
//When the object is constructed, Get the HTTP module
Http = &FHttpModule::Get();
}

// Called when the game starts or when spawned
void AHTTPActor::BeginPlay()
{
MyHttpCall();
Super::BeginPlay();
}

/*Http call*/
void AHTTPActor::MyHttpCall()
{
TSharedRef<IHttpRequest> Request = Http->CreateRequest();
Request->OnProcessRequestComplete().BindUObject(this, &AHTTPActor::OnResponseReceived);
Request->SetURL("My URL for Request");
Request->SetVerb("GET");
Request->SetHeader(TEXT("User-Agent"), "X-UnrealEngine-Agent");
Request->SetHeader("Content-Type", TEXT("application/json"));
Request->ProcessRequest();
}

void AHTTPActor::OnResponseReceived(FHttpRequestPtr Request, FHttpResponsePtr Response, bool     bWasSuccessful)
{
//Declare json as string variable
FString JsonString = Response->GetContentAsString();
//Create a pointer to hold the json serialized data
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
//Create a reader pointer to read the json data
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonString);

//Deserialize the json data given Reader and the actual object to deserialize
if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
{
	
	TArray<TSharedPtr<FJsonValue>> mainArray = JsonObject->GetArrayField("person");


                   // HOW TO ACCESS MY OBJECT FROM ARRAY HERE?
}
else
{
	GEngine->AddOnScreenDebugMessage(1, 2.0f, FColor::Red, FString("error, failed to deserialize"));
}
}

I’m unable to access the values of array after completion of request.What am i doing wrong ?
Any help will be appricated.

Lucky for you I just finished coding this exact thing. This code goes on line 48 of your CPP file:

TArray<FPersonInfo> PersonInfos;

for (int RowNum = 0; RowNum != mainArray.Num(); RowNum++) {
	FPersonInfo tempPersonInfo;
	TSharedPtr<FJsonObject> tempRow = mainArray[RowNum]->AsObject();
	tempPersonInfo.first_name = tempRow ->GetStringField("first_name");
	tempPersonInfo.referal_code = tempRow ->GetStringField("referal_code");
	tempPersonInfo.last_name = tempRow ->GetStringField("last_name");    
	PersonInfos.Add(tempPersonInfo);
}

Then in my system I take the PersonInfos array and pass it to a blueprintable event so it can be consumed in blueprints, but you can do whatever you want with it.

@Dartanlla Thanks a ton!
Worked completely fine.