Php 从Android应用程序的数据库解析JSON时出错。(未定义标记)

Php 从Android应用程序的数据库解析JSON时出错。(未定义标记),php,android,mysql,json,Php,Android,Mysql,Json,我创建了一个json,用于在android和ios中获取新闻应用程序的mysql数据。每当我解析json.php文件时,它都会返回“No tag defined”,并且应用程序在android和ios上都停止工作。下面是我试图编写的代码示例 <?php header('content-type: application/json; charset=utf-8'); $con = mysql_connect("localhost","####","###"); if (!$con

我创建了一个json,用于在android和ios中获取新闻应用程序的mysql数据。每当我解析json.php文件时,它都会返回“No tag defined”,并且应用程序在android和ios上都停止工作。下面是我试图编写的代码示例

    <?php
header('content-type: application/json; charset=utf-8');

$con = mysql_connect("localhost","####","###");

if (!$con){

            die('Could not connect: ' . mysql_error());
}

mysql_select_db("###", $con);

$date = date('Y-m-d');
//$date = '2014-02-01';
$year = substr($date, 0, -6);
$month = substr($date, 5, -3);
$day = substr($date,-2, 10);

     if($month==01) $month1="january";
else if($month==02) $month1="february";
else if($month==03) $month1="march";
else if($month==04) $month1="april";
else if($month==05) $month1="may";
else if($month==06) $month1="june";
else if($month==07) $month1="july";
else if($month==08) $month1="august";
else if($month==09) $month1="september";
else if($month==10) $month1="october";
else if($month==11) $month1="november";
else if($month==12) $month1="december";

$table=$month1.$year;
//$table = $february2014;


if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ''){

    $tag = $_REQUEST['tag'];

    if($tag =='category_page' && isset($_REQUEST['menu_id']) && $_REQUEST['menu_id'] !='' ) {

         $menu_id = $_REQUEST['menu_id'];

                try{

                        $i=0;
                        $query = mysql_query("SELECT * FROM $table WHERE menu_id=1 AND news_date ='$date'");

                        if($query === FALSE) {
                            die(mysql_error());
                        }

                        while($data=mysql_fetch_array($query)){

                        $responce[$i]['news_id'] = $data['news_id'];
                        $responce[$i]['news_title'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_title']),0,110)));
                            $responce[$i]['news_reporter'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_reporter']),0,110)));
                            $responce[$i]['news_details'] = str_replace("\t",'',str_replace("\r\n\t",'', substr(strip_tags($data['news_details']),0,110)));
                            $responce[$i]['photo'] = $data['photo'];
                            $responce[$i]['path'] = 'admin/'.str_replace('\\','',$data['path']);
                            $responce[$i]['menu_id'] = $data['menu_id'];
                            $responce[$i]['menu_type'] = $data['menu_type'];
                            $responce[$i]['news_publish_status'] = $data['news_publish_status'];
                            $responce[$i]['news_order'] = $data['news_order'];
                            $responce[$i]['news_date'] = $data['news_date'];
                            $responce[$i]['news_time'] = $data['news_time'];
                            $responce[$i]['added_by'] = $data['added_by'];
                            $responce[$i]['directory'] = $data['directory'];
                            $responce[$i]['read_number'] = $data['read_number'];
                            $responce[$i]['comment_number'] = $data['comment_number'];
                            $responce[$i]['news_comment_table_name'] = $data['news_comment_table_name'];    

                            $i++;
                        }

                    } catch(Exception $e) {

                        $responce = 'Exception: '.$e->getMessage();

                    }

     }else{

         $responce = "category or Menu id is not Defined";
     }

    echo json_encode($responce);
}else{

   echo json_encode("No tag Defined");

}
?>
试试这个

if(isset($_REQUEST['tag'])){ 
而不是

if(isset($_REQUEST['tag']) && $_REQUEST['tag'] != ''){ 

$tag=$_请求['tag'];你是怎么得到这个$tag的?它只是一个空字符串吗?是的,只是一个空字符串。好吧,在您的代码中,如果$tag是空的,它将转到另一部分,即echo json_encode(“未定义标记”)$标记不应该是空的。基本上它应该获取菜单id。@Sagar在这种情况下,有什么替代方法可以这样做,但输出是空的,不能在phpmyadmin中进行sql查询,看看您是否可以获取数据?“SELECT*FROM$table,其中menu_id=1和news_date='$date'”SELECT*FROM may2015,其中menu_id=1和news_date='2015-05-23'返回dataPrint值$response,不带json_encode,并查看它是否打印?没有输出,即使我在考虑是否有必要使用mysql查询上方的标记使用此块