Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/222.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将Android JSONArray发送到xamp服务器_Php_Android_Json_Arraylist_Android Asynctask - Fatal编程技术网

Php 将Android JSONArray发送到xamp服务器

Php 将Android JSONArray发送到xamp服务器,php,android,json,arraylist,android-asynctask,Php,Android,Json,Arraylist,Android Asynctask,我正在使用ArrayList存储购物车。然后我将ArrayList转换为JSONArray,将其传递给服务器。但是当我在PHP中解码JSONArray时,它会给出null。它给了我们安卓的一面 03-02 20:48:38.546: E/JSON Parser(16949): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObj

我正在使用
ArrayList
存储购物车。然后我将
ArrayList
转换为
JSONArray
,将其传递给服务器。但是当我在
PHP
中解码
JSONArray
时,它会给出
null
。它给了我们安卓的一面

03-02 20:48:38.546: E/JSON Parser(16949): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject 
签出
向服务器发送数据的页面

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

    @Override
    protected String doInBackground(String... args) {
        // TODO Auto-generated method stub
        AddtoCart obj = (AddtoCart) getApplicationContext();

    obj.getCart().toString()));

        JSONArray cart = new JSONArray(obj.getCart());
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("username", username);
        params.put("email", email);
        params.put("payment", payment);
        params.put("address", useraddress);
        params.put("contact", contact);
        params.put("city", usercity);
        params.put("cartitems", cart.toString());

        Log.d("params", params.toString());

        JSONObject json = jParser.makeHttpRequest(url_all_products, "POST", params);
        try {

            int success = json.getInt("success");

            if (success == 1) {
                Toast.makeText(Checkout.this, json.getString("message"), Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(Checkout.this, json.getString("message"), Toast.LENGTH_LONG).show();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
return null;
    }

}

params.toString()
的输出是什么?
org.json.JSONException:
提供完整的堆栈trace@PrerakSola我在上面展示了
params.toString()
的输出结果是什么?
org.json.JSONException:
提供完整的堆栈trace@PrerakSola我在上面展示了它
   class SaveOrder extends AsyncTask<String, String, String> {

    @Override
    protected String doInBackground(String... args) {
        // TODO Auto-generated method stub
        AddtoCart obj = (AddtoCart) getApplicationContext();

    obj.getCart().toString()));

        JSONArray cart = new JSONArray(obj.getCart());
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("username", username);
        params.put("email", email);
        params.put("payment", payment);
        params.put("address", useraddress);
        params.put("contact", contact);
        params.put("city", usercity);
        params.put("cartitems", cart.toString());

        Log.d("params", params.toString());

        JSONObject json = jParser.makeHttpRequest(url_all_products, "POST", params);
        try {

            int success = json.getInt("success");

            if (success == 1) {
                Toast.makeText(Checkout.this, json.getString("message"), Toast.LENGTH_LONG).show();
            } else {
                Toast.makeText(Checkout.this, json.getString("message"), Toast.LENGTH_LONG).show();
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
return null;
    }

}
require_once __DIR__ . '/db_connect.php';

$db = new DB_CONNECT();
if($_SERVER['REQUEST_METHOD']=="POST"){

$userName=$_POST['username'];
$userEmailId=$_POST['email'];
$userPayment=$_POST['payment'];
$userAddress=$_POST['address'];
$userContact=$_POST['contact'];
$userCity=$_POST['city'];
$status='new';
$date=strftime('%y-%m-%d'); 
$array = array();

$array = $_POST['cartitems'];   //jsonArray
$resp2 = array(stripslashes($array));

$array2 = array(json_decode($array)); 
switch (json_last_error()) {
    case JSON_ERROR_NONE:
        $error = ' - No errors';
    break;
    case JSON_ERROR_DEPTH:
        $error =' - Maximum stack depth exceeded';
    break;
    case JSON_ERROR_STATE_MISMATCH:
       $error =' - Underflow or the modes mismatch';
    break;
    case JSON_ERROR_CTRL_CHAR:
        $error = ' - Unexpected control character found';
    break;
    case JSON_ERROR_SYNTAX:
        $error =' - Syntax error, malformed JSON';
    break;
    case JSON_ERROR_UTF8:
        $error = ' - Malformed UTF-8 characters, possibly incorrectly encoded';
    break;
    default:
        $error = ' - Unknown error';
    break;
}

$count=count($_POST['cartitems']);

$sql="INSERT INTO orders (customer_name, customer_emailId, customer_city, shipping_address, payment_method, contact_no, ordered_on,status) VALUES('$userName','$userEmailId','$userCity' ,'$userAddress','$userPayment','$userContact','$date','$status')";
mysql_query($sql);

$order_id = mysql_insert_id(); 
$sql2="insert into `orders_details` (`order_id`,`product_id`,`prodName`,`prodImg`,`catName`,`requied_qty`) values ";
for ($i=0; $i<$count; $i++) {
    $sql2.="('$order_id', '{$array2[$i]['prodId']}', '{$array2[$i]['name']}', '{$array2[$i]['image']}', '{$array2[$i]['category']}', {$array2[$i]['Quantity']})";
            if ($i < ($count - 1)) {
                $sql2 .= ", ";
            }
        }
        echo $sql2; 
    if (mysql_query($sql2)) {

        $response['message']="success full inserted";
        $response['success']=1;
        echo json_encode($response);
    } 
    else
     {
        $response['message']="failed to insert";
        $response['success']=0;
        echo json_encode($response);
}


}
?>