解析Json in PHP,打印指定区域

Parsing Json in PHP, Printing specified area

我正在尝试从 json 结果中打印 php json 值(在文件中)。

我能够获取数组形式的内容,但打印出来时遇到问题: 那是我的 json 文件:

{
   "GetUsers":[
      {
         "Language":"English",
         "Name":"WhosebugIsGreate",
         "UserId":"182024",
         "UserName":"ZiomusGorliczanin"
      }
   ],
   "Result":"Success",
   "Reason":""
}

谁能帮我获取 json 文件的用户名和语言? 谢谢。 我只需要打印但不知道如何存档?

有对象来自 json:

object(stdClass)#1 (3) { ["GetUsers"]=> array(1) { [0]=> object(stdClass)#2 (4) { ["Language"]=> string(7) "English" ["Name"]=> string(21) "WhosebugIsGreate" ["UserId"]=> string(6) "182024" ["UserName"]=> string(17) "ZiomusGorliczanin" } } ["Result"]=> string(7) "Success" ["Reason"]=> string(0) "" } 

或数组:

array(3) { ["GetUsers"]=> array(1) { [0]=> array(4) { ["Language"]=> string(7) "English" ["Name"]=> string(21) "WhosebugIsGreate" ["UserId"]=> string(6) "182024" ["UserName"]=> string(17) "ZiomusGorliczanin" } } ["Result"]=> string(7) "Success" ["Reason"]=> string(0) "" } 

谢谢。

如果你想要对象:

$decoded = json_decode($json);
echo $decoded->GetUsers[0]->UserName;

或者如果你想要数组:

$decoded = json_decode($json, true);
echo $decoded['GetUsers'][0]['UserName'];

使用json_decode()

$j_decod = json_decode($json,true);

    echo j_decod['GetUsers'][0]['UserName'];  // Will return user name

    echo j_decod['GetUsers'][0]['Language'];  // Will return language