-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using in Unreal Engine - handling custom types conversion #495
Comments
I haven't tried it, but it should be sufficient to define a void to_json(json& j, const person& p) {
j = TCHAR_TO_UTF8(*value);
} (I just copied the Then you should be able to execute for an |
What you need to do is to remove the template <>
struct adl_serializer<FString> { ... }; |
@nlohmann I don't understand how that could work. How it can know to use global @theodelrieu Tried that and now I am getting...
|
For types that belong to you, the free function is the best approach usually, however for those which are not in your namespaces that' s not really intended. I think that error means that you should put this piece of code at the very top of your file, because my_type mt;
// adl_serializer<my_type> gets instantiated here
json j = mt; If you don't put your specialization before , you get that error message. |
Ok, looks like that this actually works... void to_json(json& j, const FString& value) {
j = TCHAR_TO_UTF8(*value);
} However when I am trying to dump that JSON now, I am getting bunch of japanese characters :)
json result;
FString test = TEXT("MyTest");
result["key"] = test;
UE_LOG(LogTemp, Warning, TEXT("JSON %s"), result.dump().c_str()); I am not entirely sure I got that conversion to Also I had to use |
Since FString is defined in the global namespaces, this is much more easier indeed. Edit: about the conversion , I never used unreal, I don't think I can be of any help here... |
@FredyC I am also not an expert. To make sure, you could change the function to void to_json(json& j, const FString& value) {
j = std::string(TCHAR_TO_UTF8(*value));
} and then try: json result;
FString test = TEXT("MyTest");
result["key"] = test;
std::cout << result << std::endl; The first change makes the conversion to a |
Well first change did not help and sadly it's not possible to use Anyway, I will try to figure that out on side of UE. Thanks for help! |
You're welcome. I shall close this issue. But it would be great if you could share your further experience with the library and UE. |
@FredyC, have you found any solution with this? |
@rrafis Sorry, I don't remember really, I've left Unreal Engine world shortly after this issue. |
UE_LOG_UTF8 will fix that |
Hi. I come from a JavaScript world where working with JSON is total breeze. We are currently working on a game using Unreal Engine 4 and we need to develop custom save system using JSON format so it can be read using Javascript somewhere else.
I kinda like approach of this library as its syntax is similar to what I am used to from JS. Sadly me as total rookie to C++ I am struggling with this a lot. I would like to make some arbitrary conversions from Unreal types to ones supported by this library.
For example here is a header file for FString type. Somewhere else I've found what I need to do for conversion to
std::string
so I've tried to add followingHowever this is failing compilation with this error. I am totally clueless what that means. Can you please help?
The text was updated successfully, but these errors were encountered: