Giter Site home page Giter Site logo

jsonbrother_document's Introduction

JSON Data Brother

LANGUAGE: English, 简体中文

INTRODUCE

This plug-in can easily process JSON data and message them back to your server.

I have no work experience but I know I can use php ECHO to return the data I want.

For example, you need a function to query user data and this function can be run on UNITY or UNREAL ENGINE. You may search for SQL plug-ins in UNITY MARKET or EPIC MARKET, but it will be very troublesome. (You need twice as much work)

If we implement this function on PHP and then use the HTTP REQUEST function of UNITY or UNREAL ENGINE to query the SQL data, this will become very simple.

SUMMARY

This plug-in has two parts: Json Handler and Json Sender. Their names are the same as their functions.

Name Function
Json Handler Serialize your JsonObject or deserialize your JsonString.
You can modify the value of the field after deserialization or just read their values.
Json Sender Message json data to your php and receive data returned by php echo.

JSON HANDLER

I don't want this plugin to be toooo complex, so I only gave it simple GET and SET functions, which is enough to complete my stupid workflow.

Note that you cannot directly replace an array object with other array object

JSON SENDER

Because of some limitations of UE C++, this function (JsonSender) cannot be separated from an object, so I made it into a component, which will work well in my cute Actor.

This node will create a HTTP REQUEST POST which MIME type is set to Application/json; Charset="UTF8" . When the web is loaded, the OnRequestCompletee delegate will be broadcast.


How does my PHP return data?

First, Create a blank php like this.

Second, Type the php code like this

<?php 
echo "Shader makes me full of power!";
?>

Third, Open your browser and open php page

As you can see, only your ECHO CONTENT on the whole page.

This is the result that the website will return to our program. (CallbackDelegate->Content)

image-20230111220500579

So, if we write this php in a more complex way...

<?php
	if($mode == "query")
	{
		$username = YOUR QUERY CODE;
		echo $username;
	}

	if($mode == "delete")
	{
		YOUR DELETE CODE;
		echo "Successful";
	}

	if($mode == "add")
	{
		YOUR ADD CODE;
		echo "Successful";
	}
?>

Can you imagine that your work has been transferred to PHP!

You are no longer limited by SQL plug-ins.

No matter what program you are developing, As long as your platform can message HTTP REQUEST, it can connect with your php system!


How to check my php return data in BP?

First, Add a JsonSender ActorComponent to your Actor

image-20230111223616711

Second, Create node like this

This will bind the function for the delegate OnRequestCompletee.

image-20230111223726726

Third, Create a CustomEvent for the red "Event"

image-20230111223828458

And you will see this node, Content variable is your php return data.

image-20230111223913962

Fourth, Print the content

image-20230111224039510

Fifth, Send JSON String to your php

My php will return the value of the mode field. You can find the PHP code below.

image-20230111224214411

<?php
	header("content-type:text/html;charset=utf-8");
	$jsonString = file_get_contents("php://input");
	$jsonObject = json_decode($jsonString);
	echo $jsonObject->mode;
?>

Sixth, Place actor to your level

image-20230111224639682

Final, Play or Simulate

image-20230111224800615


How to get Field Value?

First, deserialize your JSON String into JSON Object

You can put the basic format of JSON String on your PHP server to dynamically update them.

image-20230112102403092

Second, use GetJsonValue node to get the value in the JSON Object

This will return a structure to get the type pointed by the Type enumeration.

image-20230112102642244

Third, use Break node to obtain the data in the structure

image-20230112102843348

And you will get such a structure.

image-20230112102906569

The data on the structure corresponds one-to-one with the type of the GetJsonValue node.

image-20230112103031485

Fourth, Print String

image-20230112103206575

Blueprint overview.

image-20230112103233999

Final, Play or Simulate.

As you can see, the value of mode is printed.

image-20230112103356357


How to modify the Value of a Field?

First, deserialize your JSON String into JSON Object.

image-20230112103608775

Second, create a SetJsonValue node and set it correctly

The FieldType variable is the type of this Field. If the type is wrong, it will LOG ERROR.

image-20230112103726356

Third, create a structure for ValueStruct

image-20230112103909778

image-20230112103937584

The data in the structure is one-to-one corresponding to FieldType.

Set array value to other array object is not allowed.

image-20230112104030287

Fourth, enter a new value in the structure

image-20230112104304778

Fifth, add a GetJsonValue node after the SetJsonValue node

image-20230112104414743

Sixth, create the structure and Print the String in the structure as before

image-20230112104514354

Final, Play or Simulate

TESTTTT has been modified to You are clear.

image-20230112104644619


How to modify the Value of Field in an array element?

First, write a complex JSON String

This JSON has a StudentList array and two elements.

Each element can be regarded as a JSON Object.

I like to use the Make Literal String node to organize complex string data.

image-20230112105056269

{
 "StudentList":
 [
   {
    "Name":"Bob",
    "Age":"18"
   },
   {
    "Name":"Billy",
    "Age":"19"
   }
 ]
}

Second, get the Field of the array element and break the structure

image-20230112105647600

Third, get JSON Object in the array

image-20230112110019683

Fourth, set the Value of Name Field to Lisa

image-20230112123018474

So far, we have successfully changed Bob to Lisa. Next we will print this Name Value.

Fifth, output the value of the Name Field in the first JsonObject in the StudentList array

image-20230112124421392

Sixth, connect JsonObject with the original JsonObject

The return value of the SetJsonValue node is an element of the array, so we need to connect the JsonObject to the original JsonObject Root.

image-20230112124654331

Final, Play or Simulate

As you can see, Bob in JsonObject has been changed to Lisa.

image-20230112125002968

jsonbrother_document's People

Contributors

wyverncoder avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.