I need to delete the first and last quotes of a string which come from android Studio with Json format but send this Json as a string of characters or a Json Object here I leave the code in android
private void insertar() {
RequestQueue queue = Volley.newRequestQueue(getActivity());
final JSONObject datos = new JSONObject();
try {
datos.put("idnummodelo", "25469" );
datos.put("idsubnummodelo", "78");
datos.put("idestado", "2");
datos.put("idtipodemodelo", "4");
datos.put("idclasificaciondeseguridad", "1");
datos.put("idpiedefirma", "56");
datos.put("nombredescriptivo", "Android new");
datos.put("periodicidad", "2");
datos.put("aproximacion", "4");
datos.put("idsistemadeinformacion", "ONEI");
datos.put("notametodologica", "blah");
datos.put("denominaciondelpie", "Sistema");
datos.put("primercargo", "blah");
datos.put("segundocargo", "blah");
datos.put("notadecertificacion", "blah");
} catch (JSONException e) {
// handle exception
Toast.makeText(getActivity(), "JSONException", Toast.LENGTH_SHORT).show();
}
Toast.makeText(getActivity(), datos.toString(), Toast.LENGTH_LONG).show();
JsonObjectRequest putRequest = new JsonObjectRequest(Request.Method.POST, "http://" + JSON_ARRAY_REQUEST_IP + "/api/vista/plantilla.php?accion=InsertarEncuesta", datos,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response) {
// response
Toast.makeText(getActivity(), response.toString(), Toast.LENGTH_SHORT).show();
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// error
Toast.makeText(getActivity(), error.toString(), Toast.LENGTH_SHORT).show();
}
}
) {
@Override
public Map<String, String> getHeaders()
{
Map<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
return headers;
}
@Override
public byte[] getBody() {
try {
Log.i("json", datos.toString());
return datos.toString().getBytes("UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
};
queue.add(putRequest);
}
This returns this result when I print with
Toast.makeText(getActivity(), response.toString(), Toast.LENGTH_SHORT).show();
datos = "{"idnummodelo":"25469","idsubnummodelo":"78", "idestado":"2","idtipodemodelo":"4","idclasificaciondeseguridad":"1","idpiedefirma":"56", "nombredescriptivo":"Android new","periodicidad":"2","aproximacion":"4","idsistemadeinformacion":"ONEI","notametodologica":"blah","denominaciondelpie":"Sistema","primercargo":"blah","segundocargo":"blah","notadecertificacion":"blah"}"
I would like to delete the quotes to get a Json so I can work on it like this:
$Ariel = ($_POST['datos']);
$obj= json_decode($Ariel);
include '../modelo/dao-api.php';
$ob = new daoApi();
$result=$ob->InsertarEncuesta($obj);
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
echo json_encode('Esto inserto correctamente');