0

アプリケーションがデータベースに値を正しく入力するのに、json から Android アプリケーションに返される値が NULL になるのはなぜですか?

問題は Web にありますが、これはブラウザからは正常に機能します。

関数 json_last_error () は 0 を返します。

私のphpコード:

<?php

$usuario = $_POST['usuario'];
$passw = $_POST['password'];
$cpassw = $_POST['cpassword'];

$res = 0;

require_once 'funciones_bd.php';
$db = new funciones_BD();

if($db->isuserexist($usuario,$passw)){
    // echo(" Este usuario ya existe ingrese otro diferente!");
    $res = 1;       
}else{
    if($db->adduser($usuario,$passw)) { 
        // echo(" El usuario fue agregado a la Base de Datos correctamente.");          
        $res = 2;               
    }else{
        // echo(" ha ocurrido un error.");
        $res = 3;

    }

}
if ($res==2) {
    $resultado[]=array("logstatus"=>"1");
}
else {
    $resultado[]=array("logstatus"=>"0");
}
echo json_encode($resultado);
echo json_last_error();
?>

私のログキャット:

10-03 18:59:43.991: I/Choreographer(5426): Skipped 32 frames!  The application may be doing too much work on its main thread.
10-03 18:59:50.261: D/InputEventConsistencyVerifier(5426): KeyEvent: ACTION_UP but key was not down.
10-03 18:59:50.261: D/InputEventConsistencyVerifier(5426):   in android.widget.EditText{4110cd60 VFED..CL .F....I. 15,497-465,546 #7f050004 app:id/edpassword}
10-03 18:59:50.261: D/InputEventConsistencyVerifier(5426):   0: sent at 27274938000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=27274938, downTime=27274788, deviceId=0, source=0x101 }
10-03 18:59:53.090: D/InputEventConsistencyVerifier(5426): KeyEvent: ACTION_UP but key was not down.
10-03 18:59:53.090: D/InputEventConsistencyVerifier(5426):   in android.widget.EditText{4110f430 VFED..CL .F....ID 15,575-465,624 #7f050007 app:id/reppassword}
10-03 18:59:53.090: D/InputEventConsistencyVerifier(5426):   0: sent at 27277780000000, KeyEvent { action=ACTION_UP, keyCode=KEYCODE_TAB, scanCode=15, metaState=0, flags=0x8, repeatCount=0, eventTime=27277780, downTime=27277671, deviceId=0, source=0x101 }
10-03 18:59:57.960: D/dalvikvm(5426): GC_CONCURRENT freed 502K, 9% free 6389K/7016K, paused 136ms+182ms, total 661ms
10-03 18:59:58.300: E/getpostresponse(5426):  result= <br />
10-03 18:59:58.300: E/getpostresponse(5426): <font size='1'><table class='xdebug-error xe-notice' dir='ltr' border='1' cellspacing='0' cellpadding='1'>
10-03 18:59:58.300: E/getpostresponse(5426): <tr><th align='left' bgcolor='#f57900' colspan="5"><span style='background-color: #cc0000; color: #fce94f; font-size: x-large;'>( ! )</span> Notice: Undefined index: cpassword in C:\wamp\www\android\adduser.php on line <i>5</i></th></tr>
10-03 18:59:58.300: E/getpostresponse(5426): <tr><th align='left' bgcolor='#e9b96e' colspan='5'>Call Stack</th></tr>
10-03 18:59:58.300: E/getpostresponse(5426): <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>
10-03 18:59:58.300: E/getpostresponse(5426): <tr><td bgcolor='#eeeeec' align='center'>1</td><td bgcolor='#eeeeec' align='center'>0.0000</td><td bgcolor='#eeeeec' align='right'>142712</td><td bgcolor='#eeeeec'>{main}(  )</td><td title='C:\wamp\www\android\adduser.php' bgcolor='#eeeeec'>..\adduser.php<b>:</b>0</td></tr>
10-03 18:59:58.300: E/getpostresponse(5426): </table></font>
10-03 18:59:58.300: E/getpostresponse(5426): [{"logstatus":"1"}]0
10-03 18:59:58.300: E/log_tag(5426): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONArray
10-03 18:59:58.300: D/JSON(5426): null
10-03 18:59:59.264: E/JSON(5426): ERROR
10-03 18:59:59.300: E/onPostExecute=(5426): err
10-03 18:59:59.580: I/Choreographer(5426): Skipped 35 frames!  The application may be doing too much work on its main thread.
10-03 19:00:07.201: W/IInputConnectionWrapper(5426): showStatusIcon on inactive InputConnection
4

1 に答える 1

0

アプリは XDebug エラー メッセージと次の値を受け取ります。

[{"logstatus":"1"}]0

末尾に があるため、これは有効な JSON ではありません0。したがって、アプリはこれを JSON 配列として解析できません。

まず、その PHP の問題を修正する必要があります。どうやらcpasswordPOST リクエストには含まれていません。これを追加する必要があるか、使用する前に存在するかどうかを確認する必要があるかもしれません。

次に、PHP の次の行をコメントアウトしてみてください。

echo json_last_error();

その後、アプリは応答を JSON として適切に解析できるはずです。

于 2013-10-03T19:28:11.007 に答える