如何从json输出中获取确切的对象

时间:2014-06-09 11:22:11

标签: php json

我有一个json编码输出,如

"[{"COLUMN_NAME":"htag"},{"COLUMN_NAME":"title"},{"COLUMN_NAME":"sounds"},{"COLUMN_NAME":"recx"}]"

我想在数组中单独获取列名,并在相同的php文件中回显它

CODE: 这就是我所做的

$sql=mysql_query("SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='dbname' 
    AND `TABLE_NAME`='tbname'");
while($row=mysql_fetch_assoc($sql))
$out[] = $row;
$reds =  json_encode($out);

1 个答案:

答案 0 :(得分:1)

  

我想在数组

中单独获取列名

小变化:

$sql=mysql_query("SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='dbname' 
    AND `TABLE_NAME`='tbname'");
while($row=mysql_fetch_assoc($sql))
    $out[] = $row['COLUMN_NAME'];

//Column names are now in the array $out.
$reds =  json_encode($out);