有这样个json.txt 文件
{
"programmers": [
{ "firstName": "Brett", "lastName":"McLaughlin", "email": "[email protected]" },
],
"authors": [
{ "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
],
"musicians": [
{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
]
}
现在需要读取类别的名字!! (即取到programmers、authors、musicians的值)
急!哪位大师知道呀?
{
"programmers": [
{ "firstName": "Brett", "lastName":"McLaughlin", "email": "[email protected]" },
],
"authors": [
{ "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
],
"musicians": [
{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" },
]
}
现在需要读取类别的名字!! (即取到programmers、authors、musicians的值)
急!哪位大师知道呀?
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
var_dump($contents);
var_dump(json_decode($contents);
$fileName = 'json.txt';$fileContent = @file_get_contents($fileName);if($fileContent){
$fileArray = json_decode($fileContent, true);
var_dump(array_keys($fileArray));
}
$name = array_keys((array)$json);
echo "<pre>".var_export($name,true)."</pre>";