PHP JSON NULL
There is an array of this:
Array ( [0] = = Array ( [Name] = + 192.168.1.250 [id] = 3232236026 [items] + = array ( [Defualt] = = Array ( [parentnode] = 3232236026 [name] = = Please select interface [ID] + 0 ) [0] = = Array ( [ParentNode] = 3232236026 [name] = LAN0 (intranet) [id] = em0 ) [1] = = Array ( [ParentNode] = 3232236026 [Name] = LAN1 (extranet) [id] = em1 ) )))
I changed it to Utf-8 before I resolved it with mb_convert_encoding ().
I use Json_encode parsing, in the Linux terminal with PHP xxx.php directly execute, can get the correct result:
[{"Name": "192.168.1.250", "id": "3232236026", "items": {"Defualt": {"parentnode": "3232236026", "name": "\u8bf7\u9009\ U62e9\u63a5\u53e3 "," id ":" 0 "}," 0 ": {" parentnode ":" 3232236026 "," name ":" LAN0 (\u5185\u7f51) "," id ":" em0 "}," 1 ": {" ParentNode ":" 3232236026 "," name ":" LAN1 (\u5916\u7f51) "," id ":" Em1 "}}]
But when I opened it with Firefox's Web console, I got the following results:
[{"Name": "192.168.1.250", "id": "3232236026", "items": {"Defualt": {"parentnode": "3232236026", "name": "\u8bf7\u9009\ U62e9\u63a5\u53e3 "," id ":" 0 "}," 0 ": {" parentnode ":" 3232236026 "," name ": null," id ":" em0 "}," 1 ": {" parentnode ":" 3232236026 "," name ": null," id ":" Em1 "}}]
Above the "Please select Interface" This string, I entered in PHP directly, and "LAN1 (extranet)" is I get in a file, they have what is different? How to solve it?
Reply to discussion (solution)
1. Json_encode can only process utf-8 data (can be redefined with namespaces)
2, your PHP program is utf-8, so "Please select interface" can be encoded
3, your data file is not utf-8, so "LAN1 (extranet)", etc., can not be encoded
The workaround is to save the data file in Utf-8 encoding
Reply 1L,
I edit the environment is GBK, so I directly in the PHP editor input "Please select Interface", the use of mb_convert_encoding () changed to Utf-8,
"LAN1 (External Network)" is the same, from another file obtained, also use mb_convert_encoding () changed to Utf-8.
So I php xxx.php execute this PHP file can pass, get the correct result LAN1 (\u5916\u7f51), is the Web console in Firefox open to get the result is null,
I Baidu a bit, some people say that the file is generated with C, inside with a, I replaced the LAN1 (external network) may have, the result is the same.
Don't you use a statement like this in your program?
$s = Json_encode ($ar);
After you add
Echo Base64_encode (serialize ($ar));
Post the results
Czoyodm6ilt7im5hbwuioiixotiumty4ljeumjuwiiwiawqioiizmjmymjm2mdi2iiwiaxrlbxmionsizgvmdwfsdci6eyjwyxjlbnrob2rlijoimzizmjizn Jayniisim5hbwuioijcdthizjdcdtkwmdlcdtyyztlcdtyzytvcdtuzztmilcjpzci6ijaifswimci6eyjwyxjlbnrob2rlijoimzizmjiznjayniisim5hbw Uioijmqu4wkfx1nte4nvx1n2y1mskilcjpzci6imvtmcj9lcixijp7inbhcmvude5vzguioiizmjmymjm2mdi2iiwibmftzsi6ikxbtjeoxhu1ote2xhu3zju xksisimlkijoizw0xin19fv0iow==
[{"Name": "192.168.1.250", "id": "3232236026", "items": {"Defualt": {"parentnode": "3232236026", "name": "\u8bf7\u9009\ U62e9\u63a5\u53e3 "," id ":" 0 "}," 0 ": {" parentnode ":" 3232236026 "," name ":" LAN0 (\u5185\u7f51) "," id ":" em0 "}," 1 ": {" ParentNode ":" 3232236026 "," name ":" LAN1 (\u5916\u7f51) "," id ":" Em1 "}}]
Above is the Echo Base64_encode (Serialize ($ar));
The following is the result of direct printing.
You put out a problem, and you stick it out.
[Root@localhost php]# php select_for_interface.php
PHP warning:directive ' register_globals ' is deprecated in PHP 5.3 and greater in Unknown on line 0
Czoyodm6ilt7im5hbwuioiixotiumty4ljeumjuwiiwiawqioiizmjmymjm2mdi2iiwiaxrlbxmionsizgvmdwfsdci6eyjwyxjlbnrob2rlijoimzizmjizn Jayniisim5hbwuioijcdthizjdcdtkwmdlcdtyyztlcdtyzytvcdtuzztmilcjpzci6ijaifswimci6eyjwyxjlbnrob2rlijoimzizmjiznjayniisim5hbw Uioijmqu4wkfx1nte4nvx1n2y1mskilcjpzci6imvtmcj9lcixijp7inbhcmvude5vzguioiizmjmymjm2mdi2iiwibmftzsi6ikxbtjeoxhu1ote2xhu3zju xksisimlkijoizw0xin19fv0iow==
[{"Name": "192.168.1.250", "id": "3232236026", "items": {"Defualt": {"parentnode": "3232236026", "name": "\u8bf7\u9009\ U62e9\u63a5\u53e3 "," id ":" 0 "}," 0 ": {" parentnode ":" 3232236026 "," name ":" LAN0 (\u5185\u7f51) "," id ":" em0 "}," 1 ": {" ParentNode ":" 3232236026 "," name ":" LAN1 (\u5916\u7f51) "," id ":" Em1 "}}]
[Root@localhost php]#
Above is the result of my operation, this result seems to be normal, but open with the browser is not normal:
Czoynte6ilt7im5hbwuioiixotiumty4ljeumjuwiiwiawqioiizmjmymjm2mdi2iiwiaxrlbxmionsizgvmdwfsdci6eyjwyxjlbnrob2rlijoimzizmjizn Jayniisim5hbwuioijcdthizjdcdtkwmdlcdtyyztlcdtyzytvcdtuzztmilcjpzci6ijaifswimci6eyjwyxjlbnrob2rlijoimzizmjiznjayniisim5hbw uiom51bgwsimlkijoizw0win0sijeionsicgfyzw50tm9kzsi6ijmymziymzywmjyilcjuyw1lijpudwxslcjpzci6imvtmsj9fx1dijs=
[{"Name": "192.168.1.250", "id": "3232236026", "items": {"Defualt": {"parentnode": "3232236026", "name": "\u8bf7\u9009\ U62e9\u63a5\u53e3 "," id ":" 0 "}," 0 ": {" parentnode ":" 3232236026 "," name ": null," id ":" em0 "}," 1 ": {" parentnode ":" 3232236026 "," name ": null," id ":" Em1 "}}]
This is the result recorded in the browser.
I want you to give the data before the Json_encode, as if my #3 description is not ambiguous?
ytoxontpoja7ytozontzojq6im5hbwuio3m6mtm6ije5mi4xnjgums4yntaio3m6mjoiawqio3m6mta6ijmymziymzywmjyio3m6ntoiaxrlbxmio2e6mzp7c zo3oijkzwz1ywx0ijthojm6e3m6mta6inbhcmvude5vzguio3m6mta6ijmymziymzywmjyio3m6ndoibmftzsi7czoxntoi6k+ 36ycj5oup5o6l5y+ Jijtzoji6imlkijtzoje6ijaio31poja7ytozontzojewoijwyxjlbnrob2rlijtzojewoiizmjmymjm2mdi2ijtzojq6im5hbwuio3m6mti6ikxbtjao5yaf 572rksi7czoyoijpzci7czozoijlbtaio31poje7ytozontzojewoijwyxjlbnrob2rlijtzojewoiizmjmymjm2mdi2ijtzojq6im5hbwuio3m6mti6ikxbt jeo5asw572rksi7czoyoijpzci7czozoijlbteio319fx0=
Didn't look carefully ...
UrlEncode in JSON, and then back in decode, I don't know.
[{"name": "192.168.1.250", "id": "3232236026", "items": {"Defualt": {"parentnode": " 3232236026 "," name ":" \u8bf7\u9009\u62e9\u63a5\u53e3 "," id ":" 0 "}," 0 ": {" parentnode ":" 3232236026 "," name ":" LAN0 (\ u5185\u7f51) "," id ":" em0 "}," 1 ": {" parentnode ":" 3232236026 "," name ":" LAN1 (\u5916\u7f51) "," id ":" Em1 "}}]
gave the right data again.
ytoxontpoja7ytozontzojq6im5hbwuio3m6mtm6ije5mi4xnjgums4yntaio3m6mjoiawqio3m6mta6ijmymziymzywmjyio3m6ntoiaxrlbxmio2e6mzp7c zo3oijkzwz1ywx0ijthojm6e3m6mta6inbhcmvude5vzguio3m6mta6ijmymziymzywmjyio3m6ndoibmftzsi7czoxntoi6k+ 36ycj5oup5o6l5y+ Jijtzoji6imlkijtzoje6ijaio31poja7ytozontzojewoijwyxjlbnrob2rlijtzojewoiizmjmymjm2mdi2ijtzojq6im5hbwuio3m6mti6ikxbtjao5yaf 572rksi7czoyoijpzci7czozoijlbtaio31poje7ytozontzojewoijwyxjlbnrob2rlijtzojewoiizmjmymjm2mdi2ijtzojq6im5hbwuio3m6mti6ikxbt jeo5asw572rksi7czoyoijpzci7czozoijlbteio319fx0=
Not looking carefully ...
Reply 10L, this is really the data of the array before Json_encode ().
In addition, I tested, even if read from the file is full of English, the Firefox Web console is also obtained null,
At the same time, I wrote the content in the PHP code, the Firefox Web console to get the correct results.
Conclusion: It seems that as long as it is read from the file, after Json_encode (), the Firefox Web console gets null.
But I also use from the other machine to read the content from the file, through the Json_encode () in the interface display, did not appear such a problem ah.
The browser only gets the results after the Json_encode is executed, and does not change the received data.
So if it's null, it must have been generated at Json_encode.
I want you to provide the original data that you found to be null in order to find out why the problem occurred.
Anti-ignition, if you don't want to, I'm more indifferent
The browser only gets the results after the Json_encode is executed, and does not change the received data.
So if it's null, it must have been generated at Json_encode.
I want you to provide the original data that you found to be null in order to find out why the problem occurred.
Anti-ignition, if you don't want to, I'm more indifferent
Boss, this address is a problem: http://bbs.csdn.net/topics/390507272
If you don't answer, please tell me the reason.
The browser only gets the results after the Json_encode is executed, and does not change the received data.
So if it's null, it must have been generated at Json_encode.
I want you to provide the original data that you found to be null in order to find out why the problem occurred.
Anti-ignition, if you don't want to, I'm more indifferent
The section of my 8L was really the array I json_encode () before I printed it with Print_r, which is the one that I posted in my main building.
The phenomenon is that the terminal printing results are normal, Firefox console look is abnormal, as follows:
It can be seen that the result of PHP xxx.php execution, that is, echo out of the results with LAN1 (\u5916\u7f51),
In Firefox console, Firefox receives a null result.
Then, I do the test, will read the contents of the file, not by reading, directly write dead to the PHP code,
From this can be seen, echo out of the content, and the first floor is basically the same
But you get the results here in Firefox, but not in the sky. The result is right.
At the same time, I read the file inside remove Chinese, all English, get the result is also null, feel read file, Firefox display null, not read on the normal
Not a
= = 323236026 [name] + [id] = EM0
Is that right?
The name is at least invisible, so how can you convert it correctly?
You're an Ajax app, right? Can you do it or Firefox?
But put Echo Base64_encode (serialize ($ar)); Change into
File_put_contents (' Test.txt ', Base64_encode (Serialize ($ar)));
Then post the contents of the Test.txt.
Yes, Ajax calls php,php to return a JSON object to Ajax for subsequent processing via ECHO.
Contents of Test.txt Inside:
ytoxontpoja7ytozontzojq6im5hbwuio3m6mtm6ije5mi4xnjgums4yntaio3m6mjoiawqio3m6mta6ijmymziymzywmjyio3m6ntoiaxrlbxmio2e6mzp7c zo3oijkzwz1ywx0ijthojm6e3m6mta6inbhcmvude5vzguio3m6mta6ijmymziymzywmjyio3m6ndoibmftzsi7czoxntoi6k+ 36ycj5oup5o6l5y+ Jijtzoji6imlkijtzoje6ijaio31poja7ytozontzojewoijwyxjlbnrob2rlijtzojewoiizmjmymjm2mdi2ijtzojq6im5hbwuio3m6mti6ikxbtjao5yaf 572rksi7czoyoijpzci7czozoijlbtaio31poje7ytozontzojewoijwyxjlbnrob2rlijtzojewoiizmjmymjm2mdi2ijtzojq6im5hbwuio3m6mti6ikxbt jeo5asw572rksi7czoyoijpzci7czozoijlbteio319fx0=
Here's what Firefox gets:
ytoxontpoja7ytozontzojq6im5hbwuio3m6mtm6ije5mi4xnjgums4yntaio3m6mjoiawqio3m6mta6ijmymziymzywmjyio3m6ntoiaxrlbxmio2e6mzp7c zo3oijkzwz1ywx0ijthojm6e3m6mta6inbhcmvude5vzguio3m6mta6ijmymziymzywmjyio3m6ndoibmftzsi7czoxntoi6k+ 36ycj5oup5o6l5y+ Jijtzoji6imlkijtzoje6ijaio31poja7ytozontzojewoijwyxjlbnrob2rlijtzojewoiizmjmymjm2mdi2ijtzojq6im5hbwuio047czoyoijpzci7czoz Oijlbtaio31poje7ytozontzojewoijwyxjlbnrob2rlijtzojewoiizmjmymjm2mdi2ijtzojq6im5hbwuio047czoyoijpzci7czozoijlbteio319fx0 =
File_put_contents (' Test.txt ', Base64_encode (serialize ($arr _select)));
$json = Json_encode ($arr _select);
Print_r ($arr _select);
Echo Base64_encode (Serialize ($arr _select));
echo "\ n";
Echo $json;
I should be printing out the main content of the version.
Tell me, how did you get the two pieces of data you #17?
Are they saved to a file by Firefox?
If yes, then why not?
Tell me, how did you get the two pieces of data you #17?
Are they saved to a file by Firefox?
If yes, then why not?
Those two pieces of data, test.txt inside is the executive moderator of your statement obtained, but also echo Base64_encode (serialize ($arr _select)), the result.
The second piece of data is the Firefox Web console that tracks HTTP requests and has the content of the response that Firefox prints out.
Just do not know why it is not the same, because no matter how to change, PHP inside the Linux terminal directly echo get really have LAN1 (\u5916\u7f51), and Firefox appears to be really null, this situation I also first encountered, read the document, whether there is no Chinese, The Firefox print is null,
I'm going to change a machine. Deploy my code and try to see if it's the cause of the environment.
I want you to take
File_put_contents (' Test.txt ', Base64_encode (serialize ($arr _select)));
Put it in your program and then use Firefox to access your program in the normal process
The test.txt that get is the real data.
I want you to take
File_put_contents (' Test.txt ', Base64_encode (serialize ($arr _select)));
Put it in your program and then use Firefox to access your program in the normal process
The test.txt that get is the real data.
Sorry, moderator, I changed the environment to try, but did not find the problem, and then saw you 21 floor of the hint, found to be the reason for file permissions, I directly in the Linux terminal directly execute, with the root permission, can print normally, but in the browser when printing, with the Apche permissions, insufficient permissions, So I didn't open that file.