I have three arrays generated from three functions to be made into JSON data return
But if each is echo Json_encode (), and the last data returned is three JSON objects, there is a problem resolving it.
It's best not to put three of arrays together ...
And if the JSON data is returned, the browser should also be able to identify the structure of the JSON data to show it?
What I'm returning here is a direct display of the string form ...
The statement is used
Header (' Content-type:application/json ');
Where could something go wrong?
Reply to discussion (solution)
What kind of JSON data do you need to return?
is unity returned by a method? Then you'll combine the arrays into different JSON strings, such as:
Echo json_enocde (' a ' = $a, ' b ' = = $b, ' C ' + $c));
You said there was a problem. "But if each one is echo json_encode (), the last data returned is three JSON objects, parsing is problematic."
What's the problem?
You will return the value with Var json_obj=json.parse (return data) so that it becomes a JSON object
For the page can be controlled as follows
function Func1 () {}
function Func2 () {}
function func3 () {}
$data = Array ();
$data ["func1"] = Func1 ();
$data ["func2"] = Func2 ();
$data ["func3"] = func3 ();
echo Json_encode ($data);
That would be a good way to parse it.
Although JSON is just a string, he is formatted
If the format is not correct, you cannot parse the
You output 3 JSON strings respectively, to the browser due to the format is not correct, unable to parse the
So we're going to use an array to assemble them together and then output
If you do not want to use the array, then merge into a new object, you want three data as a property, and then one-time response to the client can AH
Thank you for your answer. The solution is to only divide the output of three times the output of the bar was taught
Merge into objects, parse them into JSON, and then take different objects on the client
First put three number combinations into an array, then Json_encode.
Are all data of the same interface, why not spell it together?
PHP returns JSON data example