Access JSON object name in PHP

后端 未结 4 1806
孤城傲影
孤城傲影 2020-12-06 06:33

I have the following JSON:

{
  \"nickname\": \"xadoc\",
  \"level\": 4,
  \"loc\": \"Tulsa, OK, USA\",
  \"score\": 122597,
  \"money\": 29412.5,
  \"street         


        
4条回答
  •  再見小時候
    2020-12-06 06:59

    A simple way to extract data from Json string is to use jsone_decode() function. For example:

    $json_data = '{"nickname":"xadoc","level":4,"loc":"Tulsa}';
    $decoded_data = json_decode($json_data);
    

    Then you can simply access the members of $decoded_data using -> operator:

    echo "$decoded_data->nickname \n";
    echo "$decoded_data->level \n";
    

    And if your extracted members from $decoded_data are json strings again, then you can use json_decode() again!

提交回复
热议问题