PHP decoding json

后端 未结 5 1832
误落风尘
误落风尘 2021-01-15 18:58

could anyone here help me with php an decoding json? Im trying to decode a json api url

Here is what I have at the moment:

  $string = \'
    {
              


        
相关标签:
5条回答
  • 2021-01-15 19:40

    You can use the curly brackets syntax suggested by Gumbo:

    $json_o->workers->{"someusername.jason-laptop"}
    

    However, the best way (imo, for consistency) is to use the resulting object as an associative array:

    $object = json_decode($string, true);
    
    $object['workers']['bitcoinjol.jason-laptop']['last_share']; // 1307389634
    
    0 讨论(0)
  • 2021-01-15 19:47

    The curly braces syntax should work:

    $json_o->workers->{"someusername.jason-laptop"}
    
    0 讨论(0)
  • 2021-01-15 19:47

    - or . are not valid object property names. Try instead using json_decode($string, true) (the true stands for "decode as an associative array"), and then do $json_o['workers']['someusername.jason-laptop'].

    0 讨论(0)
  • 2021-01-15 19:56

    This should work:

    $json_o->workers['someusername.jason-laptop'];
    
    0 讨论(0)
  • 2021-01-15 19:57
     $json_o = json_decode($string);
     print_r( $json_o->workers->{"bitcoinjol.jason-laptop"} );
    
    0 讨论(0)
提交回复
热议问题