duanbi9202 2015-08-07 04:54
浏览 52
已采纳

从android php mysql数据插入应用程序获取json

This is my android json response for php mysql data insert application. please help me to get the original json from this return response or how to skip return web (HTML) table from return response (data success fully inserting to the data base table)

<br />
<font size='1'><table class='xdebug-error xe-deprecated' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
<tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\AndroidFileUpload\db_connect.php on line <i>28</i></th></tr>
<tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
<tr><th align='center' bgcolor='#eeeeec'>#</th><th align='left' bgcolor='#eeeeec'>Time</th><th align='left' bgcolor='#eeeeec'>Memory</th><th align='left' bgcolor='#eeeeec'>Function</th><th align='left' bgcolor='#eeeeec'>Location</th></tr>
<tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0010</td><td bgcolor='#eeeeec' align='right'>252784</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\AndroidFileUpload\upload_news.php' bgcolor='#eeeeec'>..\upload_news.php<b>:</b>0</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>2</td><td bgcolor='#eeeeec' align='center'>0.0020</td><td bgcolor='#eeeeec' align='right'>263888</td><td bgcolor='#eeeeec'>DB_CONNECT->__construct(  )</td><td title='C:\wamp\www\AndroidFileUpload\upload_news.php' bgcolor='#eeeeec'>..\upload_news.php<b>:</b>26</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>3</td><td bgcolor='#eeeeec' align='center'>0.0020</td><td bgcolor='#eeeeec' align='right'>263976</td><td bgcolor='#eeeeec'>DB_CONNECT->connect(  )</td><td title='C:\wamp\www\AndroidFileUpload\db_connect.php' bgcolor='#eeeeec'>..\db_connect.php<b>:</b>11</td></tr>
<tr><td bgcolor='#eeeeec' align='center'>4</td><td bgcolor='#eeeeec' align='center'>0.0020</td><td bgcolor='#eeeeec' align='right'>264792</td><td bgcolor='#eeeeec'><a href='http://www.php.net/function.mysql-connect' target='_new'>mysql_connect</a>
(  )</td><td title='C:\wamp\www\AndroidFileUpload\db_connect.php' bgcolor='#eeeeec'>..\db_connect.php<b>:</b>28</td></tr>
</table></font>

{"success":1,"message":"Product successfully created."}

at the last line of the response have needed json result. any help appreciate. thanks in advance.

here is my php code

<?php


// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['news_Title']) && isset($_POST['news_Details']) && isset($_POST['news_Image'])&& isset($_POST['news_Video']) && isset($_POST['reporter_Name']) && isset($_POST['reporter_Email']) && isset($_POST['reporter_Phone'])) {

    $news_Title = $_POST['news_Title'];
    $news_Details = $_POST['news_Details'];
    $news_Image = $_POST['news_Image'];
    $news_Video = $_POST['news_Video'];
    $reporter_Name = $_POST['reporter_Name'];
    $reporter_Email = $_POST['reporter_Email'];
    $reporter_Phone = $_POST['reporter_Phone'];

    // include db connect class
    require_once __DIR__ . '/db_connect.php';

    // connecting to db
    $db = new DB_CONNECT();

    // mysql inserting a new row
    $result = mysql_query("INSERT INTO news(news_Title, news_Details, news_Image, news_Video, reporter_Name, reporter_Email , reporter_Phone) VALUES('$news_Title', '$news_Details', '$news_Image', '$news_Video', '$reporter_Name', '$reporter_Email', '$reporter_Phone')");

    // check if row inserted or not
    if ($result) {
        // successfully inserted into database
        $response["success"] = 1;
        $response["message"] = "Product successfully created.";

        // echoing JSON response
        echo json_encode($response);

    } else {
        // failed to insert row
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";

        // echoing JSON response
        echo json_encode($response);
    }
} else {
    // required field is missing
    $response["success"] = 0;
    $response["message"] = "Required field(s) is missing";

    // echoing JSON response
    echo json_encode($response);
}

?>
  • 写回答

2条回答 默认 最新

  • du4010 2015-08-09 14:34
    关注

    Simply i solved my problem by using tricky way. but this is not the exact correct way to solve this.

    String jsonStrObj = strReturn.substring(strReturn.lastIndexOf('{') + 1);
    try {
        jObj = new JSONObject(jsonStrObj);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }
    

    Waiting for the correct answer.. thank you

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler