我们正在开发电子商务移动应用程序但是在这里我们遇到了将字符串数组传递给Json对象的问题。每当我们传递相同内容时,它会抛出日志中附加的错误。这似乎是一个额外的“\”即将出现。
请在下面找到我的代码片段:
尝试{
stFullName=Edit_FullName.getText().toString();
Log.e("BillingName",stFullName);
stEmailId=Edit_EmaiAdress.getText().toString();
stAddress=Edit_Adress.getText().toString();
stCity=Edit_City.getText().toString();
stState=Edit_State.getText().toString();
stZipCode=Edit_ZipCode.getText().toString();
stPhoneNo=Edit_MobileNumber.getText().toString();
stCountry=Edit_Country.getText().toString();
stLandmark=Edit_Landmark.getText().toString();
jsonObject1.put("BillingName",stFullName);
jsonObject1.put("BillingEmail",stEmailId);
jsonObject1.put("BillingTelephone",stPhoneNo);
jsonObject1.put("BillingCountry",stCountry);
jsonObject1.put("BillingZip",stZipCode);
jsonObject1.put("BillingCity",stCity);
jsonObject1.put("BillingState",stState);
jsonObject1.put("BillingLandmark",stLandmark);
jsonObject1.put("GrandTotal",ProductAmount);
jsonObject1.put("BillingAddress",stAddress).toString().replaceAll("\\\\","");
jsonObject1.put("DeviceID",deviceId);
jsonObject1.put("IsDifferentShipping",false);
String jsonFormattedString = jSonData;
Log.e("jsonFormattedString",jsonObject1.toString());
JSONArray jsonArray = new JSONArray();
jsonArray.put(productArray);
Log.e("productArray",productArray.toString());
productArray = productArray.toString().replaceAll("\\\\","").trim();
jsonObject1.put("ChekoutProductsModel_List",productArray.toString().replaceAll("\\\\",""));
Log.e("productArray", jsonObject1.toString().replaceAll("\\\\","").trim());
//
} catch (JSONException e) {
e.printStackTrace();
}
Log.e("object1",jsonObject1.toString());
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, Config.Url.concat(getMakePayment),
jsonObject1, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject Response) {
Log.e("jsonResponse",Response.toString());
try {
String jsonResponse=Response.getString("ResponseObject");
Log.e("ResponseBilling",jsonResponse);
if(jsonResponse.equals("Billing info save successfully!")){
Toast.makeText(context,jsonResponse,Toast.LENGTH_SHORT).show();
Intent intent=new Intent(context,ProductReview.class);
intent.putExtra("product_id",ProductCode);
intent.putExtra("stock_id",StockId);
startActivity(intent);
}
else {
Toast.makeText(context,jsonResponse,Toast.LENGTH_SHORT).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
如果有任何身体可以请检查并帮助我们。