It's just occurred to me that this is absolutely certain to be an X/Y Problem (you are asking a question based on your attempted solution rather than the original problem).
From what you have told us the actual problem could be summarised like this:
I have some code written in VB.NET which fetches JSON data. When I fetch the data from (undisclosed source) it works fine, but when I fetch it from PHP, it fails (in some unspecified way).
You have then looked at the difference, and seen that when you look at the two URLs in a browser, they appear to be formatted differently, and then assumed that this is the cause of your problem.
To test whether whitespace really is the problem should be easy: create 2 PHP files with the following content, and point your VB.NET code at each:
test_1.php
<?php
echo '{
"games": "pacman",
"level":"2",
"icon":"LINK HERE",
"topscorer":"3134000",
"nextlevel":"3",
"players":[ 21322,
43131,
84993,
8212,
501421,
7832126 ]
}';
test_2.php
<?php
echo '{ "games": "pacman", "level":"2", "icon": "LINK HERE", "topscorer": "3134000", "nextlevel": "3", "players": [ 21322, 43171, 84993, 8222, 501421, 7832126 ] }';
If test_1.php works, but test_2.php doesn't, then whitespace really is your problem. However, since both should be valid JSON, your problem must then lie in your VB.NET code - so you don't need to worry about why the two look different.
If - as I strongly suspect - both tests fail, then you need to look for some other problem. The two most likely are HTTP headers and URL access / security.
HTTP headers are sent by a web server alongside the content, and tell the browser - or, in this case, your VB.NET code - how to process that content. The most likely one to be relevant here is the Content-Type
header. By default, PHP will advertise any content it generates as text/html
, which isn't what you want. The official content type for JSON data is application/json
, and you can tell PHP to set the appropriate header with the header()
function, as follows:
<?php
header('Content-Type: application/json');
echo '{ "games": "pacman", "level":"2", "icon": "LINK HERE", "topscorer": "3134000", "nextlevel": "3", "players": [ 21322, 43171, 84993, 8222, 501421, 7832126 ] }';
The other possible problem is access to the URL itself: you may be able to access your PHP page in a browser, but your VB.NET code may not. You may have put the PHP script up on a server which is not visible from the rest of the Internet, because it is local to your network, or behind a firewall. Alternatively, there may be security restrictions on which URLs can be loaded by the VB.NET code, or a firewall blocking the server where that code is running.
This is trickier to test without knowing how your VB.NET code works, but if you just fetch the content of the URL in VB.NET without trying to process it in any way, you may be able to work out which URLs work and which don't.