tp5 converts json objects into arrays

tp5 converts json objects into arrays

It is more troublesome to convert json objects into arrays in php, or the ability of php itself to handle objects needs to be improved. In short, no good method has been found.

Why convert json objects into arrays? This is the reason for the demand

The json object type needs to be returned when logging in on the front end, so the login method must return the json object type, but the method must also be called on the server side

Then it is not appropriate to return the data in json format. Let's talk about one of the tried methods that is close to success:

$arr=collection("json object")->toArray();

But this method failed in the end, because you will find that the json object type is indeed converted to an array type, but the key name of the array has an encoding problem, so it can’t be used.

But everything can be changed on the server side. Since it is not convenient for you to handle json objects on the server side, I will make a judgment and return the json object type for the client.

The server returns array type data.

But tp5 should have a solution to this problem, and we can add it later if we find a way. Anyone who knows how to deal with it is welcome to comment below.

Guess you like

Origin blog.csdn.net/weixin_45557228/article/details/109574415