Hello!
Straight to the point;
I’m serializing an object in C# to Json, It looks like this:
List<ServerListItem> ServerList;
string result = JsonConvert.SerializeObject(ServerList);
I then try to Deserialize the same string with FJsonSerializer like this:
TArray<FWServer> servers;
TArray<TSharedPtr<FJsonValue>> JsonParsed;
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(someServers);
if (FJsonSerializer::Deserialize(JsonReader, JsonParsed))
{
for (int i = 0; i < JsonParsed.Num(); ++i)
{
auto item = JsonParsed[i]->AsObject();
FWServer s = FWServer();
s.mIpAddress = item->GetStringField("ipAddress");
s.mPort = item->GetNumberField("Port");
s.mServerName = item->GetStringField("ServerName");
servers.Add(s);
}
}
Where “someServers” is an FString with the exact same contents as “Result” from c#. With one element the deserialize returns true, with more than one element it returns false.
Thank you.
Matt.