├── .gitignore ├── Images ├── inveta.jpg ├── jsontostruct.jpg └── structtojson.jpg ├── InJson.uplugin ├── LICENSE ├── README.md ├── Resources └── Icon128.png └── Source └── InJson ├── InJson.Build.cs ├── Private ├── InJson.cpp └── InJsonBPLibrary.cpp └── Public ├── InJson.h └── InJsonBPLibrary.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Visual Studio 2015 user specific files 2 | .vs/ 3 | 4 | # Compiled Object files 5 | *.slo 6 | *.lo 7 | *.o 8 | *.obj 9 | 10 | # Precompiled Headers 11 | *.gch 12 | *.pch 13 | 14 | # Compiled Dynamic libraries 15 | *.so 16 | *.dylib 17 | *.dll 18 | 19 | # Fortran module files 20 | *.mod 21 | 22 | # Compiled Static libraries 23 | *.lai 24 | *.la 25 | *.a 26 | *.lib 27 | 28 | # Executables 29 | *.exe 30 | *.out 31 | *.app 32 | *.ipa 33 | 34 | # These project files can be generated by the engine 35 | *.xcodeproj 36 | *.xcworkspace 37 | *.sln 38 | *.suo 39 | *.opensdf 40 | *.sdf 41 | *.VC.db 42 | *.VC.opendb 43 | 44 | # Precompiled Assets 45 | SourceArt/**/*.png 46 | SourceArt/**/*.tga 47 | 48 | # Binary Files 49 | Binaries/* 50 | Plugins/*/Binaries/* 51 | 52 | # Builds 53 | Build/* 54 | 55 | # Whitelist PakBlacklist-.txt files 56 | !Build/*/ 57 | Build/*/** 58 | !Build/*/PakBlacklist*.txt 59 | 60 | # Don't ignore icon files in Build 61 | !Build/**/*.ico 62 | 63 | # Built data for maps 64 | *_BuiltData.uasset 65 | 66 | # Configuration files generated by the Editor 67 | Saved/* 68 | 69 | # Compiled source files for the engine to use 70 | Intermediate/* 71 | Plugins/*/Intermediate/* 72 | 73 | # Cache files for the editor to use 74 | DerivedDataCache/* 75 | -------------------------------------------------------------------------------- /Images/inveta.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inveta/InJson/fe41a9eb80f6d5ad308cf49faa91cabe0698e64a/Images/inveta.jpg -------------------------------------------------------------------------------- /Images/jsontostruct.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inveta/InJson/fe41a9eb80f6d5ad308cf49faa91cabe0698e64a/Images/jsontostruct.jpg -------------------------------------------------------------------------------- /Images/structtojson.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inveta/InJson/fe41a9eb80f6d5ad308cf49faa91cabe0698e64a/Images/structtojson.jpg -------------------------------------------------------------------------------- /InJson.uplugin: -------------------------------------------------------------------------------- 1 | { 2 | "FileVersion": 3, 3 | "Version": 1, 4 | "VersionName": "1.0", 5 | "FriendlyName": "InJson", 6 | "Description": "", 7 | "Category": "Other", 8 | "CreatedBy": "", 9 | "CreatedByURL": "", 10 | "DocsURL": "", 11 | "MarketplaceURL": "", 12 | "SupportURL": "", 13 | "CanContainContent": true, 14 | "IsBetaVersion": false, 15 | "IsExperimentalVersion": false, 16 | "Installed": false, 17 | "Modules": [ 18 | { 19 | "Name": "InJson", 20 | "Type": "Runtime", 21 | "LoadingPhase": "PreLoadingScreen" 22 | } 23 | ] 24 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 inveta 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # InJson 2 | ue5蓝图json库,实现json字符串与蓝图结构体的互相转换 3 | 4 | # 使用方法 5 | ## json字符串转struct 6 | ![son字符串转struct](./Images/jsontostruct.jpg) 7 | 8 | ## struct转json字符串 9 | ![struct转json字符串](./Images/structtojson.jpg) 10 | 11 | 12 | 13 | # 欢迎关注我们 14 | ![欢迎关注我们](./Images/inveta.jpg) 15 | -------------------------------------------------------------------------------- /Resources/Icon128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/inveta/InJson/fe41a9eb80f6d5ad308cf49faa91cabe0698e64a/Resources/Icon128.png -------------------------------------------------------------------------------- /Source/InJson/InJson.Build.cs: -------------------------------------------------------------------------------- 1 | // Some copyright should be here... 2 | 3 | using UnrealBuildTool; 4 | 5 | public class InJson : ModuleRules 6 | { 7 | public InJson(ReadOnlyTargetRules Target) : base(Target) 8 | { 9 | PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; 10 | 11 | PublicIncludePaths.AddRange( 12 | new string[] { 13 | // ... add public include paths required here ... 14 | } 15 | ); 16 | 17 | 18 | PrivateIncludePaths.AddRange( 19 | new string[] { 20 | // ... add other private include paths required here ... 21 | } 22 | ); 23 | 24 | 25 | PublicDependencyModuleNames.AddRange( 26 | new string[] 27 | { 28 | "Core", 29 | // ... add other public dependencies that you statically link with here ... 30 | } 31 | ); 32 | 33 | 34 | PrivateDependencyModuleNames.AddRange( 35 | new string[] 36 | { 37 | "CoreUObject", 38 | "Engine", 39 | "Slate", 40 | "SlateCore", 41 | "Json", 42 | "JsonUtilities" 43 | // ... add private dependencies that you statically link with here ... 44 | } 45 | ); 46 | 47 | 48 | DynamicallyLoadedModuleNames.AddRange( 49 | new string[] 50 | { 51 | // ... add any modules that your module loads dynamically here ... 52 | } 53 | ); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Source/InJson/Private/InJson.cpp: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #include "InJson.h" 4 | 5 | DEFINE_LOG_CATEGORY(LogInJsonModule); 6 | 7 | #define LOCTEXT_NAMESPACE "FInJsonModule" 8 | 9 | void FInJsonModule::StartupModule() 10 | { 11 | // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module 12 | 13 | } 14 | 15 | void FInJsonModule::ShutdownModule() 16 | { 17 | // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading, 18 | // we call this function before unloading the module. 19 | 20 | } 21 | 22 | #undef LOCTEXT_NAMESPACE 23 | 24 | IMPLEMENT_MODULE(FInJsonModule, InJson) -------------------------------------------------------------------------------- /Source/InJson/Private/InJsonBPLibrary.cpp: -------------------------------------------------------------------------------- 1 | #include "InJsonBPLibrary.h" 2 | #include "InJson.h" 3 | 4 | 5 | 6 | bool UInJsonBPLibrary::StructToJsonString(FString& OutJsonString, const UStruct* Struct) 7 | { 8 | check(0); 9 | return false; 10 | } 11 | 12 | bool UInJsonBPLibrary::JsonStringToStruct(const FString& JsonString, UStruct*& StructToFill) 13 | { 14 | check(0); 15 | return false; 16 | } -------------------------------------------------------------------------------- /Source/InJson/Public/InJson.h: -------------------------------------------------------------------------------- 1 | // Copyright Epic Games, Inc. All Rights Reserved. 2 | 3 | #pragma once 4 | 5 | #include "Modules/ModuleManager.h" 6 | DECLARE_LOG_CATEGORY_EXTERN(LogInJsonModule, Log, All); 7 | 8 | class FInJsonModule : public IModuleInterface 9 | { 10 | public: 11 | 12 | /** IModuleInterface implementation */ 13 | virtual void StartupModule() override; 14 | virtual void ShutdownModule() override; 15 | }; 16 | -------------------------------------------------------------------------------- /Source/InJson/Public/InJsonBPLibrary.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Kismet/BlueprintFunctionLibrary.h" 4 | #include "JsonUtilities.h" 5 | #include "InJson.h" 6 | #include "InJsonBPLibrary.generated.h" 7 | 8 | 9 | UCLASS() 10 | class UInJsonBPLibrary : public UBlueprintFunctionLibrary 11 | { 12 | GENERATED_BODY() 13 | 14 | public: 15 | UFUNCTION(BlueprintCallable, Category = "InJson", CustomThunk, meta = (CustomStructureParam = "Struct", DisplayName = "StructToJsonString")) 16 | static bool StructToJsonString(FString& OutJsonString, const UStruct* Struct); 17 | 18 | UFUNCTION(BlueprintCallable, Category = "InJson", CustomThunk, meta = (CustomStructureParam = "StructToFill", DisplayName = "JsonStringToStruct")) 19 | static bool JsonStringToStruct(const FString& JsonString, UStruct*& StructToFill); 20 | 21 | 22 | DECLARE_FUNCTION(execStructToJsonString) 23 | { 24 | P_GET_PROPERTY_REF(FStrProperty, OutJsonString); 25 | 26 | Stack.StepCompiledIn(nullptr); 27 | void* InStruct = Stack.MostRecentPropertyAddress; 28 | 29 | P_FINISH; 30 | bool bSuccess = false; 31 | 32 | FStructProperty* StructProp = CastField(Stack.MostRecentProperty); 33 | if (StructProp && InStruct) 34 | { 35 | UScriptStruct* StructType = StructProp->Struct; 36 | 37 | P_NATIVE_BEGIN; 38 | bSuccess = Inner_StructToJsonString(OutJsonString, StructType, InStruct); 39 | P_NATIVE_END; 40 | } 41 | *static_cast(RESULT_PARAM) = bSuccess; 42 | } 43 | 44 | DECLARE_FUNCTION(execJsonStringToStruct) 45 | { 46 | P_GET_PROPERTY_REF(FStrProperty, JsonString); 47 | 48 | Stack.StepCompiledIn(NULL); 49 | void* StructPtr = Stack.MostRecentPropertyAddress; 50 | FStructProperty* StructProperty = CastField(Stack.MostRecentProperty); 51 | 52 | P_FINISH; 53 | 54 | UStruct* StructDefinition = StructProperty->Struct; 55 | bool bSuccess; 56 | 57 | P_NATIVE_BEGIN 58 | 59 | bSuccess = Inner_JsonStringToStruct(JsonString, StructDefinition, StructPtr); 60 | 61 | P_NATIVE_END 62 | 63 | *static_cast(RESULT_PARAM) = bSuccess; 64 | } 65 | private: 66 | static bool Inner_StructToJsonString(FString& OutJsonString, const UStruct* StructDefinition, const void* Struct) 67 | { 68 | FJsonObjectConverter::UStructToJsonObjectString(StructDefinition, Struct, OutJsonString, 0, 0); 69 | 70 | return !OutJsonString.IsEmpty(); 71 | } 72 | static bool Inner_JsonStringToStruct(const FString& JsonString, UStruct* StructDefinition, void* StructPtr) 73 | { 74 | TSharedPtr JsonObject; 75 | const TSharedRef> JsonReader = TJsonReaderFactory<>::Create(JsonString); 76 | if (!FJsonSerializer::Deserialize(JsonReader, JsonObject) || !JsonObject.IsValid()) 77 | { 78 | UE_LOG(LogInJsonModule, Warning, TEXT("JsonObjectStringToUStruct - Unable to parse json=[%s]"), *JsonString); 79 | return false; 80 | } 81 | 82 | if (!FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), StructDefinition, StructPtr, 0, 0)) 83 | { 84 | UE_LOG(LogInJsonModule, Warning, TEXT("JsonObjectStringToUStruct - Unable to deserialize. json=[%s]"), *JsonString); 85 | return false; 86 | } 87 | 88 | return true; 89 | } 90 | }; 91 | --------------------------------------------------------------------------------