I’m having difficulties at the moment formatting this JSON array into something
that i can iterate over with a foreach loop.
I am using the JSON utility plugin. I don’t have a code for trying to format the JSON array.
What I have tried is to index the field that has its’ value as the JSON array, when converting to a string and printing, it only shows me one of the elements as oppose to all of them.
{"LaserData": "{"laser":[ {"x": 0.5, "y": 0.5}, ... {"x": 0.5, "y": 0.5} ]}" }
This is exactly how my JSON table looks from the start, The value for LaserData is a string, but it is converted to a JSON. From here I’m printing the value that i get when i Index the ‘laser’ field. It prints {"x": 0.5, "y":0.5}. I’m unsure if i’m getting the full array.
Hey @GIS_UE5, thanks for posting on the forums, welcome!
I think you’d have the best success creating a for loop that iterates over the contents of the JSON, and appends them to an array you’ve created in Blueprints.
I think the only error your’re currently getting is because you’re doing the same operations twice, and I believe that changes the type of object you’re referring to in the Blueprint.
I was thinking the same thing, the only issue is how would I index each
element? To get the field it requires a string key, the object is a JSON array
so it doesn’t have keys.
Is there a way I can get the nTH value in a JSON array using the JSON utilities plugin?
EDIT: An observed issue as well, when printing the ‘laser’ field, it returns only the first value in that array, Get Field (laser):laserArray > Load From String (laserArray):StringOut > Print String (StringOut) Prints laser[0] : {“x”: 0.5, “y”: 0.5}
@GIS_UE5,
I’m not entirely sure about a way to keep it within the JSON, just because you’d have to search within JSON’s keys as you said. In Unreal’s JSON Utilities package there is a JSON to UStruct function, which you could then iterate through as a normal array. Here’s a link to some docs to help you get started: FJsonObjectConverter | Unreal Engine Documentation
I hope this can help, and happy coding!
-Zen
Thank you Zen,
I haven’t seen that up until now, I’ll explore it and I’ll mark your
message as a solution after for anyone else facing the same problem.
Hello Zen,
Just a quick update, I’ve been trying to look into using the function in the header file
and somehow creating a function block that I can use in blueprint, Would you have
any resources on that?