0

Androidからデータを更新しようとするとプロジェクトに行き詰まり、ほぼ2日間答えを見つけようとしますが、まだ解決できません。私のlogcatには何も表示されません。

Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

しかし、私のエミュレータでは強制的に閉じません。何も起こらず、意図を変更しません。

ここに私のコードがあります

EditText  firstname,middlename,lastname,aliasname,inputgender,inputcity,inputdate,inputmonth,inputyear;

    String ID;
    Button save,cancel;

        private static final String TAG_SUCCESS = "success";

     private ProgressDialog pDialog;
     JSONParser jParser = new JSONParser();
        private static final String TAG_PRODUCT = "person";

         firstname = (EditText) findViewById(R.id.editcreatefirstname);
         middlename = (EditText) findViewById(R.id.editmiddlename);
         lastname = (EditText) findViewById(R.id.editlastname);
         aliasname = (EditText) findViewById(R.id.editaliasname);
         inputgender = (EditText) findViewById(R.id.editgender);
         inputcity = (EditText) findViewById(R.id.editcity);
         inputdate = (EditText) findViewById(R.id.editdate);
         inputmonth = (EditText) findViewById(R.id.editmonth);
         inputyear = (EditText) findViewById(R.id.edityear);
         save =(Button) findViewById(R.id.btnsave);

         save.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                new SavePerson().execute();
            }
        });


        class SavePerson extends AsyncTask<String, String, String>{

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(Update.this);
            pDialog.setMessage("Saving product ...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(true);
            pDialog.show();
        }
        @Override
        protected String doInBackground(String... args) {
            // TODO Auto-generated method stub
                String name = firstname.getText().toString();
                String middle = middlename.getText().toString();
                String last = lastname.getText().toString();
                String alias = aliasname.getText().toString();
                String gender = inputgender.getText().toString();
                String city = inputcity.getText().toString();
                String date = inputdate.getText().toString();
                String month = inputmonth.getText().toString();
                String year = inputyear.getText().toString();

                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("FirstName", name));
                params.add(new BasicNameValuePair("MiddleName", middle));
                params.add(new BasicNameValuePair("LastName", last));
                params.add(new BasicNameValuePair("AliasName", alias));
                params.add(new BasicNameValuePair("Gender", gender));
                params.add(new BasicNameValuePair("CityBirth", city));
                params.add(new BasicNameValuePair("DateBirth", date));
                params.add(new BasicNameValuePair("MonthBirth", month));
                params.add(new BasicNameValuePair("YearBirth", year));

                String url_save_product = "http://10.0.2.2/update.php?ID_Person="+ID;
                JSONObject json = jParser.makeHttpRequest(url_save_product, "POST", params);
                try {
                    int success = json.getInt(TAG_SUCCESS);
                    if (success == 1) {
                        Intent i = new Intent(getApplicationContext(),SingleView.class);
                        startActivity(i);
                    } else {

                    }
                } catch (JSONException e) {
                    // TODO: handle exception
                    e.printStackTrace();
                }
            return null;
        }
        protected void onPostExecute(String file_url){
            pDialog.dismiss();
        }
    }

これは私のPHPコードです:

<?
 include "new.php";
 $response = array();
 if (isset($_POST["ID_Person"]) && isset($_POST['FirstName']) && isset($_POST['MiddleName']) && isset($_POST['LastName'])&& isset($_POST['AliasName'])&& isset($_POST['Gender'])&& isset($_POST['CityBirth'])&& isset($_POST['DateBirth'])&& isset($_POST['MonthBirth'])&& isset($_POST['YearBirth'])) {

 $id = $_POST['ID_Person'];
 $name =  $_POST['FirstName'];
 $middle =  $_POST['MiddleName'];
 $last =  $_POST['LastName'];
 $alias =  $_POST['AliasName'];
 $gender =  $_POST['Gender'];
 $citybirth =  $_POST['CityBirth'];
 $datebirth =  $_POST['DateBirth'];
 $monthbirth =  $_POST['MonthBirth'];
 $yearbirth =  $_POST['YearBirth'];

 $query = "Update T_Person SET First_Name_Person = '$name', Middle_Name_Person =      '$middle', Last_Name_Person = '$last', Alias_Person = '$alias', Gender_Person = '$gender',  City_Birth_Person = '$citybirth', Date_Birth_Person = '$datebirth', Month_Birth_Person = '$monthbirth', Year_Birth_Person = '$yearbirth' WHERE ID_Person = '$id'";
 $hasil = sqlsrv_query($conn,$query,$response);
 $row = sqlsrv_row_affected($hasil);
 if($row){
    $response["success"] = 1;
    $response["message"] = "Product successfully created.";

    // echoing JSON response
    echo json_encode($response);
    }
 }  else {
echo 'Data gagal disimpan';
} 

?>

誰か助けてください。私はあなたの助けに感謝します

4

1 に答える 1

0

データには が含まれているようです<br(おそらく から来ていnew.phpます)。さらに、IDあなたのコードには設定されていません。

実際に何かに設定されていることを確認IDし、Web ブラウザーでページを手動で要求して出力を確認します。

于 2013-10-25T03:52:58.130 に答える