org.json.JSONException:值小于; BR java.lang.String类型不能转换成的JSONObject转换成、类型、JSONException、BR

2023-09-14 00:05:38 作者:深海不及你心

我米试图从一个机器人活动接法的DATAS我sqldatabase做一个注册页面,我米收到此错误org.json.JSONException:值

首先,可以为Android应用程序与使用PHP脚本的MySQL数据库时,有人告诉我如何调试我的程序?因为我平时使用的日志猫,但这里的错误是不清晰:•...

下面是活动code:

 公共类订阅扩展活动{

    按钮bSubscribe;
    的EditText etPwdSub,etPwdConf,etLoginSub,etNameSub,etFnSub;
    字符串结果= NULL;
    InputStream的是= NULL;
    字符串donnees =;

    保护无效的onCreate(包savedInstanceState){

        super.onCreate(savedInstanceState);

        的setContentView(R.layout.subscribe);

        etLoginSub =(EditText上)findViewById(R.id.etLoginSub);
        etPwdSub =(EditText上)findViewById(R.id.etPwdSub);
        etPwdConf =(EditText上)findViewById(R.id.etPwdConf);
        etNameSub =(EditText上)findViewById(R.id.etNameSub);
        etFnSub =(EditText上)findViewById(R.id.etFnSub);

        bSubscribe =(按钮)findViewById(R.id.bSubscribe);
        bSubscribe.setOnClickListener(新View.OnClickListener(){

            公共无效的onClick(视图v){

                模式P = Pattern.compile(+ @ + \\ [A-Z] +。);
                匹配器米= p.matcher(etLoginSub.getEditableText());

                如果(m.matches()== FALSE){

                    Toast.makeText(
                            getBaseContext(),
                            乐香榭丽舍大街的电子邮件NE对应PAS太子港格式D'UNE住址邮件,
                            Toast.LENGTH_SHORT).show();
                } 其他 {

                    //他者METHODE:etPwdSub.equals()
                    如果(etPwdSub.getEditableText()!=空
                            &功放;&安培; etPwdConf.getEditableText()!=空
                            &功放;&安培; etNameSub.getEditableText()!=空
                            &功放;&安培; etFnSub.getEditableText()!= NULL){

                        如果(etPwdSub.getEditableText()的toString()。等于(etPwdConf.getEditableText()的toString())){

                            ArrayList的<的NameValuePair> namevaluepairs中=新的ArrayList<的NameValuePair>();

                            nameValuePairs.add(新BasicNameValuePair(登录,etLoginSub.getText()的toString()));
                            nameValuePairs.add(新BasicNameValuePair(PWD,etPwdConf.getText()的toString()));
                            nameValuePairs.add(新BasicNameValuePair(姓名,etNameSub.getText()的toString())。);
                            nameValuePairs.add(新BasicNameValuePair(名字,etFnSub.getText()的toString()));

                            尝试 {
                                // commandes的HttpClient
                                HttpClient的HttpClient的=新DefaultHttpClient();


                                HttpPost httppost =新HttpPost(
                                        http://192.168.1.101/spotnshare/subscribe.php);

                                httppost.setEntity(新UrlEn codedFormEntity(namevaluepairs中));

                                HTT presponse响应= httpclient.execute(httppost);

                                HttpEntity实体= response.getEntity();
                                是= entity.getContent();

                            }赶上(例外五){
                                Log.i(taghttppost,+ e.toString());
                                Toast.makeText(getBaseContext(),e.​​toString(),Toast.LENGTH_LONG)
                                        。显示();
                            }

                            尝试 {
                                的BufferedReader读卡器=新的BufferedReader(新的InputStreamReader(
                                        是,UTF-8));

                                StringBuilder的SB =新的StringBuilder();

                                串线= NULL;

                                而((行= reader.readLine())!= NULL){
                                    sb.append(行+\ N);
                                }

                                is.close();

                                结果= sb.toString();
                            }赶上(例外五){
                                Log.i(tagconvertstr,+ e.toString());
                            }

                            尝试 {
                                JSONObject的jObj =新的JSONObject的(结果);

                                    donnees = jObj.getString(信息);

                                    意图ourIntent =新的意图(Subscribe.this,
                                            SubscribeMess.class);

                                    // OBJET魁输精管理性permettre德过时了DES变量ICI拉
                                    //变量passInfo
                                    捆绑objetbunble =新包();
                                    objetbunble.putString(信息,donnees);
                                    ourIntent.putExtras(objetbunble); //对过时巴黎OBJET丹斯欧莱雅意图

                                    //在appelle巴黎业务范围
                                    startActivity(ourIntent);

                            }赶上(JSONException E){
                                Log.i(tagjsonexp,+ e.toString());
                            }赶上(ParseException的E){
                                Log.i(tagjsonpars,+ e.toString());
                            }


                        } 其他 {
                            对话D =新的对话框(Subscribe.this);
                            d.setTitle(etPwdSub.getEditableText()++ etPwdConf.getEditableText());
                            d.show();
                        }

                    } 其他 {
                        对话D =新的对话框(Subscribe.this);
                        d.setTitle(填写所有领域!);
                        d.show();
                    }

                }
            }
        });

    }

    保护无效的onPause(){
        super.onPause();
        完();
    }
}
 

和这里的PHP脚本:

 < PHP

如果(使用isset($ _ POST ['登录'])及和放大器;使用isset($ _ POST ['PWD'])及和放大器;使用isset($ _ POST ['名称'])及和放大器;使用isset($ _ POST ['名字'])) {

    包括(connexion_bdd.php);

    如果(connexionBDD()== 1){

        $登录= $ _ POST ['登录'];
        $ PWD = $ _ POST ['PWD'];
        $名称= $ _ POST ['名称'];
        $名字= $ _ POST ['姓'];

        $ SQL =SELECT colUserID
                从用户表
                WHERE colUserLogin ='$登录。';

        $ REQ =的mysql_query($ SQL);
        $ resultat = mysql_num_rows($ REQ);

        如果($ resultat == 0){
            $临时工=时间();
            $谱号= MD5($登录$临时工。);

            $ REQ =请求mysql_query(插入用户表(colUserLogin,colUserPwd,colUserName,colUserFirstname,colUserKey,colUserDate)
                                        VALUES('$登录','$ pwd的','$名','$姓名','$谱号','$临时工'));

            如果($ REQ){
                    $ destinataire = $登录;
                    $ sujet =欢迎SNSR;
                    从$ =来源:SpotnShareReminder@live.com \ r \ N的;
                    从$ =内容类型:text / html的;字符集= US-ASCII \ r \ N的;

                    $消息='冰冻圈下面的链接:LT; BR />
                    &所述; A HREF =的http://localhost/spotnshare/validation_mail.php usrk ='$谱号。'? >
                        报名确认。
                    &所述; / a取代; ';

                    ini_set('SMTP','relay.skynet.be');

                    如果(电子邮件($ destinataire,$ sujet,$消息,从$)){
                        $味精='请检查您的邮箱激活您的帐户!;
                    }
                    其他{
                        $味精='问题向您发送的激活邮件!;
                        $ REQ =请求mysql_query(DELETE FROM用户表WHERE colUserLogin ='$伪。');
                    }
            }
            其他{
                $味精='问题插入您在我们的数据库!;
            }
        }其他{
                $味精=此邮件已被使用!;
        }
        了mysql_free_result($ REQ);

    }其他{
        $味精=Connexion的问题,德DB
        打印(json_en code(阵列(信息=> $味精)));
    }

}其他{
        $味精=无法处理您的DATAS
}

打印(json_en code(阵列(信息=> $味精)));

?>
 
无损检测Fastjson DoS漏洞以及盲区分Fastjson与Jackson组件

解决方案

由于我设法纠正一些错误2;失踪,我可以Log.i看到错误(tagconvertstr,[+结果+]);

这是显示msg是这样的事情:

[< BR />字体大小= 1表类=''Xdebug的-erroeDIR =升...的HTML code加载,这不是我最初的code,然后.... {消息:问题向您发送的激活邮件!}]

==>所以有个问题与该消息的JSON格式问题向您发送激活邮件,但用户注册OK!

所以第二次我会尝试,code它会显示我在一个正确的JSON格式:此邮件已被使用! (没有任何错误),但我仍然无法找到我的PHP code中的错误:•

I m trying to do a registration page from an android activity connectiong the datas to my sqldatabase, I m getting this error " org.json.JSONException: Value

First of all, could anyone advise me on how to debug my program when using an mysql database with php script for an android application ? Cause I usually use the log cat but here the errors aren't as clear :S ...

Here is the activity code :

public class Subscribe extends Activity {

    Button bSubscribe;
    EditText etPwdSub, etPwdConf, etLoginSub, etNameSub, etFnSub;
    String result = null;
    InputStream is = null;
    String donnees = "";

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.subscribe);

        etLoginSub = (EditText) findViewById(R.id.etLoginSub);
        etPwdSub = (EditText) findViewById(R.id.etPwdSub);
        etPwdConf = (EditText) findViewById(R.id.etPwdConf);
        etNameSub = (EditText) findViewById(R.id.etNameSub);
        etFnSub = (EditText) findViewById(R.id.etFnSub);

        bSubscribe = (Button) findViewById(R.id.bSubscribe);        
        bSubscribe.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {

                Pattern p = Pattern.compile(".+@.+\\.[a-z]+");
                Matcher m = p.matcher(etLoginSub.getEditableText());

                if (m.matches() == false) {

                    Toast.makeText(
                            getBaseContext(),
                            "Le champs email ne correspond pas au format d'une adresse mail",
                            Toast.LENGTH_SHORT).show();
                } else {

                    // autre méthode : etPwdSub.equals("")
                    if (etPwdSub.getEditableText() != null
                            && etPwdConf.getEditableText() != null
                            && etNameSub.getEditableText() != null
                            && etFnSub.getEditableText() != null) {

                        if (etPwdSub.getEditableText().toString().equals(etPwdConf.getEditableText().toString())) {

                            ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

                            nameValuePairs.add(new BasicNameValuePair("login", etLoginSub.getText().toString()));
                            nameValuePairs.add(new BasicNameValuePair("pwd", etPwdConf.getText().toString()));
                            nameValuePairs.add(new BasicNameValuePair("name", etNameSub.getText().toString()));
                            nameValuePairs.add(new BasicNameValuePair("firstname", etFnSub.getText().toString()));                          

                            try {
                                // commandes httpClient
                                HttpClient httpclient = new DefaultHttpClient();


                                HttpPost httppost = new HttpPost(
                                        "http://192.168.1.101/spotnshare/subscribe.php");

                                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                                HttpResponse response = httpclient.execute(httppost);

                                HttpEntity entity = response.getEntity();
                                is = entity.getContent();

                            } catch (Exception e) {
                                Log.i("taghttppost", "" + e.toString());
                                Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG)
                                        .show();
                            }

                            try {
                                BufferedReader reader = new BufferedReader(new InputStreamReader(
                                        is, "UTF-8"));

                                StringBuilder sb = new StringBuilder();

                                String line = null;

                                while ((line = reader.readLine()) != null) {
                                    sb.append(line + "\n");
                                }

                                is.close();

                                result = sb.toString();
                            } catch (Exception e) {
                                Log.i("tagconvertstr", "" + e.toString());
                            }

                            try {
                                JSONObject jObj = new JSONObject(result);

                                    donnees = jObj.getString("message");

                                    Intent ourIntent = new Intent(Subscribe.this,
                                            SubscribeMess.class);

                                    // objet qui vas nous permettre de passe des variables ici la
                                    // variable passInfo
                                    Bundle objetbunble = new Bundle();          
                                    objetbunble.putString("message", donnees);
                                    ourIntent.putExtras(objetbunble);               // on passe notre objet dans l'intent

                                    // on appelle notre activité
                                    startActivity(ourIntent);                                   

                            } catch (JSONException e) {
                                Log.i("tagjsonexp", "" + e.toString());
                            } catch (ParseException e) {
                                Log.i("tagjsonpars", "" + e.toString());
                            }


                        } else {
                            Dialog d = new Dialog(Subscribe.this);
                            d.setTitle(etPwdSub.getEditableText() +" "+etPwdConf.getEditableText());
                            d.show();
                        }

                    } else {
                        Dialog d = new Dialog(Subscribe.this);
                        d.setTitle("Fill in all the fields !");
                        d.show();
                    }

                }
            }
        });

    }

    protected void onPause() {
        super.onPause();
        finish();
    }
}

and here is the php script :

<?php

if( isset($_POST['login']) && isset($_POST['pwd']) && isset($_POST['name']) && isset($_POST['firstname'])) {

    include("connexion_bdd.php");

    if(connexionBDD() == 1){

        $login = $_POST['login'];
        $pwd = $_POST['pwd'];
        $name = $_POST['name'];
        $firstname = $_POST['firstname'];

        $sql = "SELECT colUserID
                FROM userTable 
                WHERE colUserLogin = '".$login."' ";

        $req = mysql_query($sql);
        $resultat=mysql_num_rows($req); 

        if($resultat==0){
            $temps = time();
            $clef = md5($login . $temps);

            $req = mysql_query("INSERT INTO userTable(colUserLogin, colUserPwd, colUserName, colUserFirstname, colUserKey, colUserDate)
                                        VALUES( '$login', '$pwd', '$name', '$firstname', '$clef', '$temps')");

            if($req){
                    $destinataire = $login;
                    $sujet ="Welcome on SnSR";
                    $from = "From: SpotnShareReminder@live.com \r\n";
                    $from .= "Content-Type: text/html; charset=us-ascii\r\n";

                    $message = ' Clic on the link below :<br/>
                    <a href="http://localhost/spotnshare/validation_mail.php?usrk='.$clef.' ">
                        Registration confirmation.
                    </a> ';

                    ini_set('SMTP','relay.skynet.be');

                    if(mail($destinataire,$sujet,$message,$from)){
                        $msg = 'Check your mailbox to activate your account !'; 
                    }           
                    else{
                        $msg = 'Problem sending you the activation mail !'; 
                        $req = mysql_query("DELETE FROM userTable WHERE colUserLogin = '".$pseudo."' ");
                    }
            }
            else{
                $msg = 'Problem inserting you in our database !';
            }
        }else{
                $msg = 'This email has already been used !';
        }
        mysql_free_result ($req);   

    }else{
        $msg = "Connexion problem with de DB"
        print(json_encode(array("message" => $msg)));       
    }

}else{
        $msg = "Couldn't treat your datas"
}

print(json_encode(array("message" => $msg)));

?>

解决方案

Thanks I manage to correct some of the errors 2 ';' were missing and I could see the error with Log.i("tagconvertstr", "["+result+"]");

The msg that it is showing is something like that :

[<br/ > font size = 1 table class=''xdebug-erroe' dir='ltr' ... loads of html code that wasn't in my initial code then....{"message":"Problem sending you the activation mail !"}]

==> so there s a problem with the json format on that message "Problem sending you the activation mail" but the user was registered OK !

So the second time i would try that code it would show me in a correct json format : "This email has already been used" ! (without any errors) but i still can't find the error in my php code :S

 
精彩推荐