用php访问json

I want to read the json data on the page http://mattrb.com/txt.txt

For example, let's say I want to get the name "Bulbasaur." I have this code:

<?php 
  $file = file_get_contents("http://mattrb.com/txt.txt"); 
  $json = json_decode($file); 
  echo $json->1->name; 
?> 

This code causes the php to simply not load. Is this because you can't use a number? Next I tried this:

<?php 
  $file = file_get_contents("http://mattrb.com/txt.txt"); 
  $json = json_decode($file);
  $num = 1;
  echo $json->$num->name; 
?>

This allows the php to load, but still returns nothing. What am I doing wrong?

Your json should not contain newline and other invalid characters. In other words - your json is invalid. json_decode does not work on the file.

$file = file_get_contents("http://mattrb.com/txt.txt");
var_dump(json_decode($file));
// NULL

Your json is invalid. Please check at http://jsonlint.com/.

Also you can access "1" in php like this: echo $json->{1}->name;

Your json file isn't valide You have a comma problem item number 135 try to delete it so you can parse the file .

"135": {,    //the problem of your json data is here
    "levels": [5, 15],
    "probability": 4 "name": "Jolteon",
    "attack": 65,
    "defense": 60,
    "type": "electric",
    "moves": [
        "tackle",
        "thundershock",
        "thunder"
    ],
    "curve": 1.6
},