简体   繁体   English

[英]Value <br of type java.lang.String cannot be converted to JSONObject

i have been trying to come up with a form where trainee can apply for makeup lessons and when they submit the data will be stored in a database. 我一直在尝试提出一种表格,学员可以在此表格上化妆课,而当他们提交化妆数据时,这些数据将存储在数据库中。 I am new to android programming and I am also using the php to connect to the database. 我是android编程的新手,我也使用php连接数据库。

i have no idea where the codes went wrong 我不知道代码哪里出了问题

This is my error: 这是我的错误:

08-01 14:04:42.808: E/JSON Parser(5907): Error parsing data org.json.JSONException:      Value <br of type java.lang.String cannot be converted to JSONObject
08-01 14:18:03.149: I/tagconvertstr(5965): [null]
08-01 14:18:03.149: W/dalvikvm(5965): threadid=15: thread exiting with uncaught exception (group=0x40a71930)
08-01 14:18:03.308: E/AndroidRuntime(5965): FATAL EXCEPTION: AsyncTask #5
08-01 14:18:03.308: E/AndroidRuntime(5965): java.lang.RuntimeException: An error occured while executing doInBackground()
08-01 14:18:03.308: E/AndroidRuntime(5965):     at android.os.AsyncTask$3.done(AsyncTask.java:299)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:352)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at java.util.concurrent.FutureTask.setException(FutureTask.java:219)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at java.util.concurrent.FutureTask.run(FutureTask.java:239)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:230)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at java.lang.Thread.run(Thread.java:856)
08-01 14:18:03.308: E/AndroidRuntime(5965): Caused by: java.lang.NullPointerException
08-01 14:18:03.308: E/AndroidRuntime(5965):     at com.example.testmakeup.Makeup$CreateMakeup.doInBackground(Makeup.java:288)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at com.example.testmakeup.Makeup$CreateMakeup.doInBackground(Makeup.java:1)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at android.os.AsyncTask$2.call(AsyncTask.java:287)
08-01 14:18:03.308: E/AndroidRuntime(5965):     at java.util.concurrent.FutureTask.run(FutureTask.java:234)
08-01 14:18:03.308: E/AndroidRuntime(5965):     ... 4 more

My Android Codes: 我的Android代码:

import android.app.Activity;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.app.TimePickerDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TabHost;
import android.widget.TimePicker;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import android.widget.DatePicker;

public class Makeup extends Activity {
Button AbsentDate;
Button MakeupDate;
Button MakeupTime;
Button Submit;
private int year;
private int month;
private int day;
private int hour;
private int minute;
static final int DATE_DIALOG_ID = 999;
static final int DATE_DIALOG_ID_1 = 1;
static final int TIME_DIALOG_ID = 2;

private EditText name, trainee_id, batch_id, module_name, reason, remarks;
private String department;
private String makeuptime;
private String makeupdate;
private String absentdate;  

private static String Makeup_URL = "http://10.0.2.2/MajorProject/TestMakeup/NewMakeUp.php";
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
// JSON parser class
private ProgressDialog pDialog; 
JSONParser jsonParser = new JSONParser();

public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

        setContentView(R.layout.makeup);            
        TabHost tabs=(TabHost)findViewById(R.id.tabhost); 
        tabs.setup(); 
        TabHost.TabSpec spec=tabs.newTabSpec("tag1"); 
        spec.setContent(R.id.tab1); 
        spec.setIndicator("Make Up Form");          
        tabs.addTab(spec); 
        spec=tabs.newTabSpec("tag2"); 
        spec.setContent(R.id.tab2); 
        spec.setIndicator("Exam Claims"); 
        tabs.addTab(spec);
        tabs.setCurrentTab(0);          
        setCurrentDateOnView();
        addListenerOnButton();
        setCurrentTimeOnView();

        name = (EditText)findViewById(R.id.Name);
        trainee_id =(EditText)findViewById(R.id.TranineeID);
        batch_id = (EditText)findViewById(R.id.BatchID);
        module_name = (EditText)findViewById(R.id.ModuleName);
        reason = (EditText)findViewById(R.id.Reason);
        remarks = (EditText)findViewById(R.id.Remarks); 

         Spinner Spin = (Spinner) findViewById(R.id.spinner1);

            ArrayAdapter<CharSequence> adapter =          ArrayAdapter.createFromResource(this,
                    R.array.DeptName, android.R.layout.simple_spinner_item);
         // Apply the adapter to the spinner
            Spin.setAdapter(adapter);           
            Spin.setOnItemSelectedListener(new MyOnItemSelectedListener());
} 

public class MyOnItemSelectedListener implements OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {

       department = parent.getItemAtPosition(pos).toString();
    }

    public void onNothingSelected(AdapterView parent) {
        // Do nothing.
    }
}

public void setCurrentDateOnView() { 

    AbsentDate = (Button)findViewById(R.id.AbsentDate);
    MakeupDate = (Button)findViewById(R.id.MakeupDate);     
    final Calendar c = Calendar.getInstance();
    year = c.get(Calendar.YEAR);
    month = c.get(Calendar.MONTH);
    day = c.get(Calendar.DAY_OF_MONTH); 
    // set current date into button
    AbsentDate.setText(new StringBuilder()
    // Month is 0 based, just add 1
    .append(day).append("-").append(month + 1).append("-")
    .append(year).append(" "));     
    // set current date into button
    MakeupDate.setText(new StringBuilder()
    // Month is 0 based, just add 1
    .append(day).append("-").append(month + 1).append("-")
    .append(year).append(" ")); 

}   

public void setCurrentTimeOnView(){ 

    MakeupTime = (Button) findViewById(R.id.MakeupTime);        
    final Calendar c = Calendar.getInstance();
    hour = c.get(Calendar.HOUR_OF_DAY);
    minute = c.get(Calendar.MINUTE); 
    // set current time into textview
    MakeupTime.setText(new StringBuilder().append(pad(hour))
    .append(":").append(pad(minute)));

} 

public void addListenerOnButton() {

    AbsentDate = (Button)findViewById(R.id.AbsentDate);

    AbsentDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DATE_DIALOG_ID);
        }
    });     
    MakeupDate = (Button)findViewById(R.id.MakeupDate);

    MakeupDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DATE_DIALOG_ID_1);
        }
    });     
    MakeupTime = (Button) findViewById(R.id.MakeupTime);         
    MakeupTime.setOnClickListener(new View.OnClickListener() { 
        @Override
        public void onClick(View v) { 
            showDialog(TIME_DIALOG_ID);
        }
    });     
    Submit =(Button)findViewById(R.id.Submit);
    Submit.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            new CreateMakeup().execute();
        }
    }); 
}

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DATE_DIALOG_ID:
       // set date picker as current date
       return new DatePickerDialog(this, datePickerListener, 
                     year, month,day);
    case DATE_DIALOG_ID_1:
           // set date picker as current date
           return new DatePickerDialog(this, datePickerListener1, 
                         year, month,day);
    case TIME_DIALOG_ID:
        // set time picker as current time
        return new TimePickerDialog(this, 
                                    timePickerListener, hour, minute,false);
    }   
    return null;
}  
private DatePickerDialog.OnDateSetListener datePickerListener = new DatePickerDialog.OnDateSetListener() {
    // when dialog box is closed, below method will be called.
    public void onDateSet(DatePicker view, int selectedYear,
        int selectedMonth, int selectedDay) {
    year = selectedYear;
    month = selectedMonth;
    day = selectedDay;  
    // set selected date into textview
    AbsentDate.setText(new StringBuilder().append(month + 1)
       .append("-").append(day).append("-").append(year)
       .append(" "));   
    absentdate= AbsentDate.toString();
    }
}; 

private DatePickerDialog.OnDateSetListener datePickerListener1 = new DatePickerDialog.OnDateSetListener() {

    // when dialog box is closed, below method will be called.
    public void onDateSet(DatePicker view, int selectedYear,
        int selectedMonth, int selectedDay) {
    year = selectedYear;
    month = selectedMonth;
    day = selectedDay;  
    // set selected date into textview
    MakeupDate.setText(new StringBuilder().append(month + 1)
       .append("-").append(day).append("-").append(year)
       .append(" "));       
    makeupdate= MakeupDate.toString();      
    }
};

   private TimePickerDialog.OnTimeSetListener timePickerListener = 
        new TimePickerDialog.OnTimeSetListener() {
    public void onTimeSet(TimePicker view, int selectedHour,
            int selectedMinute) {
        hour = selectedHour;
        minute = selectedMinute;

        // set current time into timebutton
        MakeupTime.setText(new StringBuilder().append(pad(hour))
                .append(":").append(pad(minute)));

        makeuptime = MakeupTime.toString();         
    }
};
private static String pad(int c) {
    if (c >= 10)
       return String.valueOf(c);
    else
       return "0" + String.valueOf(c);
}   
 class CreateMakeup extends  AsyncTask<String, String, String> {          
     boolean failure = false;
    private String result;      
           @Override
     protected void onPreExecute() {
            super.onPreExecute();
           pDialog = new ProgressDialog(Makeup.this);
           pDialog.setMessage("Submiting...");
           pDialog.setIndeterminate(false);
           pDialog.setCancelable(true);
           pDialog.show();
     }
        @Override
        protected String doInBackground(String... args) {
            // TODO Auto-generated method stub
             // Check for success tag
            int success;
            String Name = name.getText().toString();
            String Department = department;
            String Trainee_id = trainee_id.getText().toString();
            String Batch_id = batch_id.getText().toString();
            String Absent_date = absentdate;
            String Module_name = module_name.getText().toString();
            String Absentreason = reason.getText().toString();
            String Makeup_date = makeupdate;
            String Makeup_time = makeuptime;
            String Remarks = remarks.getText().toString();                          
            try {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("name", Name));
                params.add(new BasicNameValuePair("department", Department));
                params.add(new BasicNameValuePair("trainee_id", Trainee_id));
                params.add(new BasicNameValuePair("batch_id", Batch_id));
                params.add(new BasicNameValuePair("absentdate",Absent_date));
                params.add(new BasicNameValuePair("module_name", Module_name));
                params.add(new BasicNameValuePair("reason", Absentreason));
                params.add(new BasicNameValuePair("makeupdate", Makeup_date));
                params.add(new BasicNameValuePair("makeuptime", Makeup_time));
                params.add(new BasicNameValuePair("remarks",  Remarks));    

               Log.d("request!", "starting");

                JSONObject json = jsonParser.makeHttpRequest(
                        Makeup_URL, "POST", params);

                            // Async json success tag
                            success = json.getInt(TAG_SUCCESS);
                            if (success == 1) {
                                Log.d("Submitted", json.toString());
                                finish();                                   
                                return json.getString(TAG_MESSAGE);
                            } else {
                                Log.d("Fail to Submit!", json.getString(TAG_MESSAGE));
                                return json.getString(TAG_MESSAGE);
                            }

            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }           
}
}

and my php file: 和我的PHP文件:

<?php
$response = array();

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

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

// get all products from products table
if (!empty($_POST)) {
//initial query
$query = "INSERT INTO make up ( Trainnee_Name, Department, Trainnee_ID, Batch_ID, Absent_Date, Module_Name, Reason_For_Absent, Makeup_Date, Makeup_Time, Remarks )
 VALUES ( :Trainnee_Name, :Department, :Trainnee_ID, :Batch_ID, :Absent_Date, :Module_Name, :Reason_For_Absent, :Makeup_Date, :Makeup_Time, :Remarks) ";

//Update query
$query_params = array(
    ':Trainnee_Name' => $_POST['name'],
    ':Department' => $_POST['pepartment'],
    ':Trainnee_ID' => $_POST['trainnee_id']
    ':Batch_ID' => $_POST['batch_id']
    ':Absent_Date' => $_POST['absentdate']
    ':Module_Name' => $_POST['module_name']
    ':Reason_For_Absent' => $_POST['reason']
    ':Makeup_Date' => $_POST['Makeupdate']
    ':Makeup_Time' => $_POST['Makeuptime']
    ':Remarks' => $_POST['remarks']
);

//execute query
try {
    $stmt   = $db->prepare($query);
    $result = $stmt->execute($query_params);
}
catch (PDOException $ex) {
    // For testing, you could use a die and message. 
    //die("Failed to run query: " . $ex->getMessage());

    //or just use this use this one:
    $response["success"] = 0;
    $response["message"] = "Database Error. Couldn't add post!";
    die(json_encode($response));
}

$response["success"] = 1;
$response["message"] = "Post Successfully Added!";
echo json_encode($response);

} 

?>

Part of JSONParser.java JSONParser.java的一部分

public JSONObject makeHttpRequest(String url, String method,
        List<NameValuePair> params) { 

if(method == "POST"){
            // request method is POST
            // defaultHttpClient
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost(url);
            httpPost.setEntity(new UrlEncodedFormEntity(params));

            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
            is = httpEntity.getContent();

 try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
    } catch (Exception e) {
        Log.e   ("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

}

I think on line JSONObject json = jsonParser.makeHttpRequest(Makeup_URL, "POST", params); 我认为在线JSONObject json = jsonParser.makeHttpRequest(Makeup_URL, "POST", params); returns invalid Json . 返回无效的Json As per the error log the response is <br> or starts with <br> . 根据错误日志,响应为<br>或以<br>开头。 Which is getting failed while parsing. 解析时失败。 As a result your json object is Null . 结果,您的json对象为Null And it gives Null Pointer Exception on Line 288 . 并且它在Line 288给出了Null Pointer Exception

Will you please check why its not returning JSON. 您能否检查一下为什么它不返回JSON。 You will have to be extra sure that the response should be JSON. 您将必须特别确保响应应为JSON。

Android Studio org.json.JSONException:值<br of type java.lang.String cannot be converted to JSONObject< div><div id="text_translate"><p> 我正在尝试使用 volley 将一些数据发布到服务器。</p><p> 问题似乎与编码的字符串图像有关。</p><p> 在这条线上</p><pre> String name = namefield.getText().toString(); String age = agefield.getText().toString(); String gender = genderfield.getText().toString(); String color = colorfield.getText().toString(); String notes = notesfield.getText().toString(); String images = encodeImage(bitmap); updatedetails(name, age, gender, color, notes, String.valueOf(owner), String.valueOf(id), images);</pre><p> 如果我将图像更改为空字符串</p><pre> updatedetails(name, age, gender, color, notes, String.valueOf(owner), String.valueOf(id), "");</pre><p> 然后比数据发送到服务器,这就是我知道图像是问题的方式。</p><p> 我记录了图像响应,这就是我得到的:</p><pre> Strings: /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAUAAk8DASIA AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3 ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA AwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx BhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK U1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3 uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD+8LwX /wAit4a/7F/R/wD0011z/wCrH4/+hVyPgv8A5Fbw1/2L+j/+mmuuf/Vj8f8A0Ku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g/HrxhpnivxF4L+GHhPwtqR 8DNo6ePfFfj/AMWjw/4X0bVdat5tV0TRNLjgWbWtb1maNVZ1SOC3jZo0LCVkB5vS/jR+0r4ivINL 0jS/2YtVvZQS1va/Enx074AZshIvCm48LxtUkjB5ywr4rE8WcGZXm9LhrMeMOE8oz+VODhwzV4qw 9DEuMnNr93N0qlJrm1h7NST0nBSTUurD5bmuKwdTG4bLpckUuf3oaW5m2256x1unKSdrtJ3cj78o r5J/t/8Abj/6Jp+zz/4cDx1/8y1H9v8A7cf/AETT9nn/AMOB46/+ZavtTlPraivnf4Q/FbXfGmt+ MfAPxA8GHwH8Q/A1npF/rOk2urrrvh2+0vXGuBoetaPrXlx70P8AZLK0MqLLFIGZg0jOR9EUAFFF FAHE+C/+RW8Nf9i/o/8A6aa65/8AVj8f/Qq5HwX/AMit4a/7F/R//TTXXP8A6sfj/wChVw4X/dZ/ L/0k4cL/ALrP5f8ApJYryz4p/Cf4WfHL4c+K/hT8ZfA3hz4j/DjxjY/2b4w8E+K9Ii1Tw1renGUa o0OsaPcKysDLGrEP87TFC6szmOvU6+Wv2wPCn7R3jv8AZf8AjV4I/ZI+IHg74Y/tE+J/B9/pHwk+ IPjizEvhrwh4r1FmB13XIf8AhFfGDEQaMdRMf/FK3UgumjZUSRVlHcdx/Or/AMFfv2ntN+Ivh6D/ AIN6f+CV3ws8N+LPj58VvCWk/Dz4p2XhbTY7D4PfsffAG3fSNY1ttdIUeH9A1658Py5twhL+DoZA yAfEifwPBXxB/wAF3f2U9B/Yk/4J4f8ABDn9huLxBc+Ivg78O/2wPAXgr4la9eLDpum+LNRJn1jW tZ1qONtqxzHXfHM0ZbDojudqvH5VeifsXf8ABGf/AIOKP2B7D4myfs//ALX3/BOa18V/F7xXqPjL 4mfE/wAceFPin8RPi1441WSSWTGu+OPEn7P7+ILi3eWSSYWyMoS4lMrSedtdv2</pre><p> 而其他数据响应正常,例如:</p><pre> Strings: red</pre><p> logcat 说问题出在这里:</p><pre> try { JSONObject jsonObject = new JSONObject(result); Log.i("Check", result);</pre><p> 以下是相关代码:</p><pre> public void updatedetails(final String name, final String age, final String gender, final String color, final String notes, final String owner, final String id, final String pet_image) { final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setCancelable(false); progressDialog.setMessage("Updating pet details"); progressDialog.show(); try { String url = "https://happy-paws.co.za/dogwalking/apis/v1/pet/update_pet.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener&lt;String&gt;() { @Override public void onResponse(String response) { String result = response.toString(); // Log.d("zzzz","res "+result); Toast.makeText(update.this, response, Toast.LENGTH_SHORT).show(); getDataResponse1(result); Log.i("Check", result); Log.i("Check", response); } }, new com.android.volley.Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(update.this, error.getMessage(), Toast.LENGTH_SHORT).show(); Log.d("TAG", error.getMessage()); } }) { @Override public byte[] getBody() throws com.android.volley.AuthFailureError { String str = "{\"name\":\"" + name + "\",\"age\":\"" + age + "\",\"gender\":\"" + gender + "\",\"color\":\"" + color + "\",\"notes\":\"" + notes + "\",\"owner\":\"" + owner + "\",\"id\":\"" + id + "\",\"pet_image\":\"" + pet_image + "\"}"; return str.getBytes(); } @Override protected Map&lt;String, String&gt; getParams() { Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;(); // params.put("email",email); // params.put("password",password); return params; } }; RequestQueue requestQueue = Volley.newRequestQueue(this); requestQueue.add(stringRequest); } catch (Exception e) { //App.handleUncaughtException(e); } progressDialog.dismiss(); } public void getDataResponse1(String result) { final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setCancelable(false); progressDialog.setMessage("Please Wait....."); progressDialog.show(); try { JSONObject jsonObject = new JSONObject(result); Log.i("Check", result); JSONObject current = jsonObject.getJSONObject(result); String message = current.getString("message"); String name = jsonObject.isNull("name")? null: jsonObject.getString("name"); String age = jsonObject.isNull("age")? null: jsonObject.getString("age"); String gender = jsonObject.isNull("gender")? null: jsonObject.getString("gender"); String notes = jsonObject.isNull("notes")? null: jsonObject.getString("notes"); String color = jsonObject.isNull("color")? null: jsonObject.getString("color"); // String android_status=jsonObject.getString("android_status"); if (message.equals("Pet was updated.")) { Toast.makeText(this, "" + message, Toast.LENGTH_SHORT).show(); // updatedetails(name, age, gender, color, notes, String.valueOf(owner), String.valueOf(id), pet_image); } else { Toast.makeText(this, "" + message, Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); } progressDialog.dismiss(); } private void selectImage(Context context) { final CharSequence[] options = {"Take Photo", "Choose from Gallery", "Cancel"}; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Choose your profile picture"); builder.setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals("Take Photo")) { Intent takePicture = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(takePicture, 0); } else if (options[item].equals("Choose from Gallery")) { Intent pickPhoto = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(pickPhoto, 1); } else if (options[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); } @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode:= RESULT_CANCELED) { switch (requestCode) { case 0. if (resultCode == RESULT_OK &amp;&amp; data.= null) { bitmap = (Bitmap) data;getExtras().get("data"); profilepic;setImageBitmap(bitmap); encodeImage(bitmap): } break. case 1. if (resultCode == RESULT_OK) { bitmap = (Bitmap) data;getExtras().get("data"); Uri selectedImage = data.getData(); try { InputStream inputStream = getContentResolver().openInputStream(selectedImage); bitmap = BitmapFactory.decodeStream(inputStream); profilepic;setImageBitmap(bitmap). encodeImage(bitmap); // Glide.clear(profilepic). } catch (FileNotFoundException e) { Toast,makeText(update,this. "Pet added succesfully". Toast;LENGTH_SHORT);show(); } break. } } } } public String encodeImage(Bitmap bitmap) { ByteArrayOutputStream ba = new ByteArrayOutputStream(). bitmap.compress(Bitmap,CompressFormat,JPEG; 100. ba); byte[] imagebyte = ba.toByteArray(). encode = android.util,Base64.encodeToString(imagebyte; Base64;DEFAULT); return encode; }</pre><p> 然后我提交的地方:</p><pre> updatebutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String name = namefield.getText().toString(); String age = agefield.getText().toString(); String gender = genderfield.getText().toString(); String color = colorfield.getText().toString(); String notes = notesfield.getText().toString(); String images = encodeImage(bitmap); updatedetails(name, age, gender, color, notes, String.valueOf(owner), String.valueOf(id), images); Log.d("Strings",images ); Log.d("Strings",color );</pre></div> - Android Studio org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误。 org.json.JSONException:值 - error. org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject JSONException:值 - JSONException: Value <br of type java.lang.String cannot be converted to JSONObject 值 - Value <br of type java.lang.String cannot be converted to JSONObject Android 解析数据时出错:JSONException:值 - Error parsing data : JSONException: Value <br of type java.lang.String cannot be converted to JSONObject org.json.JSONException:值 - org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject (Andriod Studio) json.JSONException错误:值 - ERROR with json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject 解析 dataorg.json.JSONException 时出错:值 - Error parsing dataorg.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject 遇到“ org.json.JSONException:值 - encountered “org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject” Android Studio org.json.JSONException:值<br of type java.lang.String cannot be converted to JSONObject< div><div id="text_translate"><p> 我正在尝试使用 volley 将一些数据发布到服务器。</p><p> 问题似乎与编码的字符串图像有关。</p><p> 在这条线上</p><pre> String name = namefield.getText().toString(); String age = agefield.getText().toString(); String gender = genderfield.getText().toString(); String color = colorfield.getText().toString(); String notes = notesfield.getText().toString(); String images = encodeImage(bitmap); updatedetails(name, age, gender, color, notes, String.valueOf(owner), String.valueOf(id), images);</pre><p> 如果我将图像更改为空字符串</p><pre> updatedetails(name, age, gender, color, notes, String.valueOf(owner), String.valueOf(id), "");</pre><p> 然后比数据发送到服务器,这就是我知道图像是问题的方式。</p><p> 我记录了图像响应,这就是我得到的:</p><pre> Strings: /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/2wBDAQEBAQEBAQEBAQEBAQEBAQEBAQEB AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQH/wAARCAUAAk8DASIA AhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQA AAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3 ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZmqKjpKWm p6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl5ufo6erx8vP09fb3+Pn6/8QAHwEA AwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREAAgECBAQDBAcFBAQAAQJ3AAECAxEEBSEx BhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYkNOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElK U1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3 uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwD+8LwX /wAit4a/7F/R/wD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响应正常,例如:</p><pre> Strings: red</pre><p> logcat 说问题出在这里:</p><pre> try { JSONObject jsonObject = new JSONObject(result); Log.i("Check", result);</pre><p> 以下是相关代码:</p><pre> public void updatedetails(final String name, final String age, final String gender, final String color, final String notes, final String owner, final String id, final String pet_image) { final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setCancelable(false); progressDialog.setMessage("Updating pet details"); progressDialog.show(); try { String url = "https://happy-paws.co.za/dogwalking/apis/v1/pet/update_pet.php"; StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener&lt;String&gt;() { @Override public void onResponse(String response) { String result = response.toString(); // Log.d("zzzz","res "+result); Toast.makeText(update.this, response, Toast.LENGTH_SHORT).show(); getDataResponse1(result); Log.i("Check", result); Log.i("Check", response); } }, new com.android.volley.Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Toast.makeText(update.this, error.getMessage(), Toast.LENGTH_SHORT).show(); Log.d("TAG", error.getMessage()); } }) { @Override public byte[] getBody() throws com.android.volley.AuthFailureError { String str = "{\"name\":\"" + name + "\",\"age\":\"" + age + "\",\"gender\":\"" + gender + "\",\"color\":\"" + color + "\",\"notes\":\"" + notes + "\",\"owner\":\"" + owner + "\",\"id\":\"" + id + "\",\"pet_image\":\"" + pet_image + "\"}"; return str.getBytes(); } @Override protected Map&lt;String, String&gt; getParams() { Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;(); // params.put("email",email); // params.put("password",password); return params; } }; RequestQueue requestQueue = Volley.newRequestQueue(this); requestQueue.add(stringRequest); } catch (Exception e) { //App.handleUncaughtException(e); } progressDialog.dismiss(); } public void getDataResponse1(String result) { final ProgressDialog progressDialog = new ProgressDialog(this); progressDialog.setCancelable(false); progressDialog.setMessage("Please Wait....."); progressDialog.show(); try { JSONObject jsonObject = new JSONObject(result); Log.i("Check", result); JSONObject current = jsonObject.getJSONObject(result); String message = current.getString("message"); String name = jsonObject.isNull("name")? null: jsonObject.getString("name"); String age = jsonObject.isNull("age")? null: jsonObject.getString("age"); String gender = jsonObject.isNull("gender")? null: jsonObject.getString("gender"); String notes = jsonObject.isNull("notes")? null: jsonObject.getString("notes"); String color = jsonObject.isNull("color")? null: jsonObject.getString("color"); // String android_status=jsonObject.getString("android_status"); if (message.equals("Pet was updated.")) { Toast.makeText(this, "" + message, Toast.LENGTH_SHORT).show(); // updatedetails(name, age, gender, color, notes, String.valueOf(owner), String.valueOf(id), pet_image); } else { Toast.makeText(this, "" + message, Toast.LENGTH_SHORT).show(); } } catch (JSONException e) { e.printStackTrace(); } progressDialog.dismiss(); } private void selectImage(Context context) { final CharSequence[] options = {"Take Photo", "Choose from Gallery", "Cancel"}; AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setTitle("Choose your profile picture"); builder.setItems(options, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int item) { if (options[item].equals("Take Photo")) { Intent takePicture = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(takePicture, 0); } else if (options[item].equals("Choose from Gallery")) { Intent pickPhoto = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(pickPhoto, 1); } else if (options[item].equals("Cancel")) { dialog.dismiss(); } } }); builder.show(); } @Override public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) { super.onActivityResult(requestCode, resultCode, data); if (resultCode:= RESULT_CANCELED) { switch (requestCode) { case 0. if (resultCode == RESULT_OK &amp;&amp; data.= null) { bitmap = (Bitmap) data;getExtras().get("data"); profilepic;setImageBitmap(bitmap); encodeImage(bitmap): } break. case 1. if (resultCode == RESULT_OK) { bitmap = (Bitmap) data;getExtras().get("data"); Uri selectedImage = data.getData(); try { InputStream inputStream = getContentResolver().openInputStream(selectedImage); bitmap = BitmapFactory.decodeStream(inputStream); profilepic;setImageBitmap(bitmap). encodeImage(bitmap); // Glide.clear(profilepic). } catch (FileNotFoundException e) { Toast,makeText(update,this. "Pet added succesfully". Toast;LENGTH_SHORT);show(); } break. } } } } public String encodeImage(Bitmap bitmap) { ByteArrayOutputStream ba = new ByteArrayOutputStream(). bitmap.compress(Bitmap,CompressFormat,JPEG; 100. ba); byte[] imagebyte = ba.toByteArray(). encode = android.util,Base64.encodeToString(imagebyte; Base64;DEFAULT); return encode; }</pre><p> 然后我提交的地方:</p><pre> updatebutton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String name = namefield.getText().toString(); String age = agefield.getText().toString(); String gender = genderfield.getText().toString(); String color = colorfield.getText().toString(); String notes = notesfield.getText().toString(); String images = encodeImage(bitmap); updatedetails(name, age, gender, color, notes, String.valueOf(owner), String.valueOf(id), images); Log.d("Strings",images ); Log.d("Strings",color );</pre></div> - Android Studio org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject java.lang.string类型的Java值无法转换为jsonobject - Java value of type java.lang.string cannot be converted to jsonobject
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM