Download

Print a Json string value


		TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject);
		JsonObject->SetStringField("Name", "Super Sword");
		JsonObject->SetNumberField("Damage", 15);
		JsonObject->SetNumberField("Weight", 3);

		FString OutputString;
		TSharedRef< TJsonWriter<> > Writer = TJsonWriterFactory<>::Create(&OutputString);
		FJsonSerializer::Serialize(JsonObject.ToSharedRef(), Writer);


		FString JsonString;


EDIT : Code snippet taken from : 



		TSharedRef< TJsonReader<> > Reader = TJsonReaderFactory<>::Create(JsonString);
		if (FJsonSerializer::Deserialize(Reader, JsonObject))
		{
			FString username =  JsonObject->GetStringField(TEXT("Name"));
			GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("As String Data ~> %s"), username));

		}



The above makes a Json object with some values.

However printing user name gives me a dead end.

0e474399dff907d324f821b11a362b0b05d69365.png

Hello there,

From the looks of it I think you feed an empty variable to the TJsonReaderFactory.

Here is how I apporached:



//Create a pointer to hold the json serialized data
	TSharedPtr<FJsonObject> JsonObject;
 
	//Create a reader pointer to read the json data
	TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(JsonString);
 
	//Deserialize the json data given Reader and the actual object to deserialize
	if (FJsonSerializer::Deserialize(Reader, JsonObject))
	{
		//Get the value of the json object by field name
		int32 recievedInt = JsonObject->GetIntegerField("customInt");
 
		//Output it to the engine
		GEngine->AddOnScreenDebugMessage(1, 2.0f, FColor::Green, FString::FromInt(recievedInt));
	}


JsonString is read from a web server with HTTP request. I suppose you should get your jsonObject and convert it to a .ToString() and feed it to the reader factory. Or I don’t even think you need a reader, as if you have the json object, you can print it already.

Thank you very much, I implement your solution, and get back to you when I can.

Raises the black flag :smiley: