To fix the errors that I had, I changed my code to the following:
void ANetworkPlayerController::ReceiveData()
{
TArray<uint8> ReceivedData;
uint32 Size;
int32 Read = 0;
while (Socket->HasPendingData(Size))
{
ReceivedData.SetNumUninitialized(FMath::Min(Size, 65507u));
Read = 0;
Socket->Recv(ReceivedData.GetData(), ReceivedData.Num(), Read);
ReceivedData.RemoveAt(Read, ReceivedData.Num() - Read, false);
TCHAR* MyString = (TCHAR*)ReceivedData.GetData();
Print(MyString);
GLog->Logf(TEXT("Json string: %s"), (TCHAR*)(ReceivedData.GetData()));
Print(StringFromBinaryArray(ReceivedData));
}
if (ReceivedData.Num() <= 0)
{
VShow("Error, the Server isn't streaming data");
}
FMemoryReader MemoryReader(ReceivedData);
TSharedRef< TJsonReader<> > Reader = TJsonReader<>::Create(&MemoryReader);
bool result = FJsonSerializer::Deserialize(Reader, JsonObject);
if (!result)
Print("Error, Json Deserialization Failed");
}
The main thing that was going wrong I believe was my setup of the JsonReader. Instead of converting to a string, and putting that through the reader, I set up an FMemoryReader object instead. That did stop the code from crashing.
However, my problem is still there, but its not my fault, aside from the fact that I was trying to access the Deserialised values, even when they didn’t exist since the function had failed. That’s to do with the software I was trying to interface with, nothing I can do now.