x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How do I properly utilize JsonObjectStringToUStruct?

I'm trying to take an object from a json http response and convert it to a UStruct. I came across the JsonObjectStringToUStruct function via JsonUtilities.h. While it looks like the solution to my problem, I'm having some issues with it. I haven't worked in c++ in forever, so please forgive me for any syntax issues. Anyway, I'm not exactly sure how to properly supply the parameters needed by this procedure. Specifically the structure definition UStruct. I'm assuming this is for mapping parameters from json into the corresponding properties of the output struct, but I'm not sure what that is supposed to look like.

Any help would be greatly appreciated. Here is the basics of what I have so far.

 const UStruct *structDefinition = {
     // What do I do with this.. if anything? 
             };
  
     FTestObjectStruct testObjectStructOut = FTestObjectStruct();
     
     bool bSomePropertiesWereWritten = FJsonObjectConverter::JsonObjectStringToUStruct(jsonResponseString, structDefinition, &testObjectStructOut, 0, 0);

Product Version: Not Selected
Tags:
more ▼

asked Mar 29 '14 at 05:40 AM in C++ Programming

avatar image

TheAggie
46 4 8 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

3 answers: sort voted first

The part you're missing is that the struct definition is a UStruct* object, which is generated as part of the automatic code generation you get when you declare something as USTRUCT in a header file. Here's an example of a UStruct definition from one of out header files

 USTRUCT()
 struct FNotificationLevelUp
 {
     GENERATED_USTRUCT_BODY()
 
     /** The new level */
     UPROPERTY()
     int32 Level;
     
     FNotificationLevelUp()
         : Level(-1)
     {
     }
 };

And here's a simple example of how to use this, where we are converting a json string into a UStruct that's allocated on the stack:

 FNotificationLevelUp LevelUpData;
 FJsonObjectConverter::JsonObjectStringToUStruct(JsonStr, LevelUpData.StaticStruct(), &LevelUpData, 0, 0)

In both examples the important part is that the field names of the UStruct match the names of the json parameters. Our JSON is using java case conventions but UProperties are case insensitive so there's some hacky code to convert field name case.

more ▼

answered Mar 31 '14 at 06:47 PM

avatar image

[Epic]Ben Zeigler STAFF
1.3k 29 129 75

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

bump. Still stuck. Any suggestions.

more ▼

answered Mar 30 '14 at 01:42 AM

avatar image

TheAggie
46 4 8 10

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Thank you very much Ben, that worked like a charm. I had everything setup correctly but wasn't aware of the StaticStruct function. I can't believe I didn't notice it w/ Intellitype. I was soooooo close. Thanks again!

more ▼

answered Mar 31 '14 at 09:29 PM

avatar image

TheAggie
46 4 8 10

avatar image IanBreeg Jun 22 '15 at 12:26 PM

This SHOULD be in the docs! StaticStruct() is a kind of a 'secret knowledge' as it is now. Thank you, Ben!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question