Foros del Web » Programando para Internet » Android »

Error parsing data org.json.JSONException

Estas en el tema de Error parsing data org.json.JSONException en el foro de Android en Foros del Web. El sgte mensaje me arroja la tratar de guardar en una bd en mysql @import url("http://static.forosdelweb.com/clientscript/vbulletin_css/geshi.css"); Código Java: Ver original Error parsing data org. json ...
  #1 (permalink)  
Antiguo 19/03/2015, 14:29
 
Fecha de Ingreso: enero-2015
Ubicación: Guayaquil
Mensajes: 17
Antigüedad: 9 años, 3 meses
Puntos: 0
Busqueda Error parsing data org.json.JSONException

El sgte mensaje me arroja la tratar de guardar en una bd en mysql
Código Java:
Ver original
  1. Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject

Este es mi codigo que realiza el insert

Código Java:
Ver original
  1. package conexion;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.logging.Level;
  6. import java.util.logging.Logger;
  7.  
  8. import json.JSONParser;
  9.  
  10. import org.apache.http.message.BasicNameValuePair;
  11. import org.json.JSONException;
  12. import org.json.JSONObject;
  13.  
  14. import android.app.Activity;
  15. import android.app.ProgressDialog;
  16. import android.os.AsyncTask;
  17. import android.os.Bundle;
  18. import android.util.Log;
  19. import android.view.View;
  20. import android.view.View.OnClickListener;
  21. import android.view.Window;
  22. import android.widget.Button;
  23. import android.widget.EditText;
  24. import android.widget.TextView;
  25. import android.widget.Toast;
  26.  
  27. import com.example.facturacion_movil.R;
  28.  
  29. public class ViewRegistrarPedido extends Activity implements OnClickListener {
  30.    
  31.     EditText editTextCan;
  32.     TextView textViewcli , textViewCodcli ,textViewfecha , textViewSubTot, textViewDscto, textViewIva,textViewTot ,textViewNumPed,
  33.     textViewdir,textViewcor,textViewruc,textViewest;
  34.     Button btnCalcular;
  35.     int valor; 
  36.     JSONParser jsonParse = new JSONParser();   
  37.     JSONObject jso = null; 
  38.     List<BasicNameValuePair> param;
  39.     Boolean respuest;
  40.     ProgressDialog pDialog;
  41.        
  42.     private final String REGISTE_URL = "http://192.168.2.158:80/tesis/register.php";
  43.  
  44.     private String codcli;
  45.     private String nomcli;
  46.     private String cedcli;
  47.     private String dircli;
  48.     private String corcli;
  49.     private String fecha;
  50.     private String num;
  51.     private Double sub;
  52.     private Double dscto;
  53.     private Double iva;
  54.     private Double tot;
  55.     private String est;
  56.    
  57.     private static final String TAG_SUCCES = "success";
  58.  
  59.     private static final String TAG_MESSAG = "message";
  60.    
  61.     @Override
  62.     protected void onCreate(Bundle savedInstanceState) {
  63.         super.onCreate(savedInstanceState);
  64.         this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  65.         setContentView(R.layout.activity_registrar_pedido);
  66.  
  67.         Bundle b = getIntent().getExtras();
  68.                
  69.         cedcli = b.getString("cedcliente");
  70.         codcli = b.getString("codcliente");
  71.         nomcli = b.getString("nomcliente");
  72.         dircli = b.getString("dircliente");
  73.         corcli = b.getString("corcliente");
  74.         fecha = b.getString("fecha");
  75.         num = b.getString("numped");
  76.         sub = b.getDouble("subtotal");
  77.         dscto = b.getDouble("dscto");
  78.         iva = b.getDouble("iva");
  79.         tot = b.getDouble("tot");
  80.         est = b.getString("est");      
  81.        
  82.         textViewNumPed.setText(num);
  83.         textViewfecha.setText(fecha);
  84.         textViewCodcli.setText(codcli);
  85.         textViewcli.setText(nomcli);
  86.         textViewdir.setText(dircli);
  87.         textViewcor.setText(corcli);
  88.         textViewruc.setText(cedcli);
  89.         textViewSubTot.setText(sub.toString());
  90.         textViewDscto.setText(dscto.toString());
  91.         textViewIva.setText(iva.toString());
  92.         textViewTot.setText(tot.toString());
  93.         textViewest.setText("F");
  94.                        
  95.         btnCalcular = (Button)findViewById(R.id.btnre);        
  96.        
  97.         btnCalcular.setOnClickListener(new OnClickListener() {
  98.            
  99.             @Override
  100.             public void onClick(View v) {
  101.                 // TODO Auto-generated method stub
  102.             new CrearPedido().execute();   
  103.             }
  104.         });        
  105.     }
  106.  
  107.     @Override
  108.     public void onClick(View v) {
  109.         // TODO Auto-generated method stub
  110.        
  111.     }
  112.    
  113.     class CrearPedido extends AsyncTask<String, String, String> {
  114.          
  115.         @Override
  116.         protected void onPreExecute() {
  117.             super.onPreExecute();
  118.             pDialog = new ProgressDialog(ViewRegistrarPedido.this);
  119.             pDialog.setMessage("Creating User...");
  120.             pDialog.setIndeterminate(false);
  121.             pDialog.setCancelable(true);
  122.             pDialog.show();
  123.         }
  124.  
  125.   @Override
  126.   protected String doInBackground(String... args) {
  127.    // TODO Auto-generated method stub
  128.     // Check for success tag
  129.             int success;
  130.            
  131.             try {            
  132.                 // Building Parameters
  133.                 param = new ArrayList<BasicNameValuePair>();
  134.                 param.add(new BasicNameValuePair("ped_num_pedido", num));
  135.                 param.add(new BasicNameValuePair("ped_fecha", fecha));
  136.                 param.add(new BasicNameValuePair("ped_cod_cliente", codcli));
  137.                 param.add(new BasicNameValuePair("ped_nom_cli", nomcli));
  138.                 param.add(new BasicNameValuePair("ped_direccion", dircli));
  139.                 param.add(new BasicNameValuePair("ped_correo", corcli));
  140.                 param.add(new BasicNameValuePair("ped_ruc", cedcli));
  141.                 param.add(new BasicNameValuePair("ped_subtotal", sub.toString()));
  142.                 param.add(new BasicNameValuePair("ped_descuento", dscto.toString()));
  143.                 param.add(new BasicNameValuePair("ped_iva", iva.toString()));
  144.                 param.add(new BasicNameValuePair("ped_total", tot.toString()));
  145.                 param.add(new BasicNameValuePair("ped_estado", "F"));
  146.                 Log.d("request!", "starting");
  147.                 //Posting user data to script
  148.                 jso = jsonParse.makeHttpRequest(REGISTE_URL, "POST", param);                
  149.                 // json success element
  150.                 success = jso.getInt(TAG_SUCCES);
  151.                 if (success == 1) {
  152.                  Log.d("Pedido Created!", jso.toString());                                
  153.                  respuest = true;
  154.                  return jso.getString(TAG_MESSAG);
  155.                 }else{
  156.                  Log.d("Pedido Failure!", jso.getString(TAG_MESSAG));
  157.                  respuest = false;
  158.                  return jso.getString(TAG_MESSAG);                
  159.                 }
  160.             } catch (JSONException e) {
  161.                 Log.i("error puto",e.toString());
  162.                 e.printStackTrace();
  163.                 e.getMessage();
  164.                 Logger.getLogger(ViewRegistrarPedido.class.getName()).log(Level.SEVERE, null, e);
  165.             }
  166.  
  167.             return jso.toString();
  168.    
  169.   }
  170.  
  171.         protected void onPostExecute(String file_url) {        
  172.             // dismiss the dialog once product deleted
  173.             pDialog.dismiss();
  174.             runOnUiThread(new Runnable() {
  175.                 @Override
  176.                 public void run() {
  177.                     // TODO Auto-generated method stub
  178.                     if (respuest == true) {                    
  179.                         Toast.makeText(getApplicationContext(), "Pedido Realizado", Toast.LENGTH_SHORT).show();                    
  180.                        
  181.                     } else if (respuest == false) {
  182.                         Toast.makeText(getApplicationContext(), "Pedido No Realizado", Toast.LENGTH_SHORT).show();
  183.                     }
  184.                 }
  185.             });            
  186.             if (file_url != null){
  187.              Toast.makeText(ViewRegistrarPedido.this, file_url, Toast.LENGTH_LONG).show();
  188.             }
  189.         }
  190.  }
.

Y este mi archivo php.
Código PHP:
<?php

require("config.inc.php");
if (!empty(
$_POST)) {
    
    
$query "INSERT INTO pedido(ped_num_pedido,ped_fecha,ped_cod_cliente,ped_nom_cli,ped_direccion,ped_correo,ped_ruc,ped_subtotal,ped_descuento,ped_iva,ped_total,ped_estado)"
            
" VALUES ('$ped_num_pedido','$ped_fecha','$ped_cod_cliente' ,'$ped_nom_cli','$ped_direccion' ,'$ped_correo' ,'$ped_ruc' ,'$ped_subtotal' ,'$ped_descuento' ,'$ped_iva','$ped_tot','$ped_estado') ";
    
//$query = "INSERT INTO pedido(ped_cod_cliente,ped_nom_cli,ped_direccion,ped_correo,ped_ruc,ped_estado) VALUES (:ped_cod_cliente ,:ped_nom_cli,:ped_direccion,:ped_correo,:ped_ruc,:ped_estado)";
    
$query_params = array(
        
':ped_num_pedido' => $_POST['num_pedido'],
        
':ped_fecha' => $_POST['fecha'],
        
':ped_cod_cliente' => $_POST['cod_cliente'],
        
':ped_nom_cli' => $_POST['nom_cliente'],
        
':ped_direccion' => $_POST['dir'],
        
':ped_correo' => $_POST['cor'],
        
':ped_ruc' => $_POST['ruc'],
        
':ped_subtotal' => $_POST['subt'],
        
':ped_descuento' => $_POST['desc'],
        
':ped_iva' => $_POST['iva'],
        
':ped_tot' => $_POST['tot'],
        
':ped_estado' => $_POST['est']            
    );

    
//ejecutamos la query y creamos el usuario
    
try {
        
$stmt $db->prepare($query);
        
$result $stmt->execute($query_params);
    } catch (
PDOException $ex) {
    

        
$response["success"] = 0;
        
$response["message"] = "Error base de datos";
        die(
json_encode($response));
    }
    
$response["success"] = 1;
    
$response["message"] = "El usuario se ha agrego";
    echo 
json_encode($response);
} else {
    
?>
    <h1>Register</h1> 
    <form action="register.php" method="POST"> 
        Nª Pedido:<br/> 
        <input type="text" name="num_pedido" value="" /> 
        <br/><br/> 
        Fecha:<br/> 
        <input type="text" name="fecha" value="" /> 
        <br/><br/> 
        Cod Cli:<br/> 
        <input type="text" name="cod_cliente" value="" /> 
        <br/><br/> 
        Nom Cli:<br/> 
        <input type="text" name="nom_cliente" value="" /> 
        <br/><br/> 
        Direccion:<br/> 
        <input type="text" name="dir" value="" /> 
        <br/><br/> 
        Correo:<br/> 
        <input type="text" name="cor" value="" /> 
        <br/><br/> 
        Ruc:<br/> 
        <input type="text" name="ruc" value="" /> 
        <br/><br/> 
        Subtotal:<br/> 
        <input type="text" name="subt" value="" /> 
        <br/><br/> 
        Dscto:<br/> 
        <input type="text" name="desc" value="" /> 
        <br/><br/> 
        IVA:<br/> 
        <input type="text" name="iva" value="" /> 
        <br/><br/> 
        Total:<br/> 
        <input type="text" name="tot" value="" /> 
        <br/><br/> 
        Estado:<br/> 
        <input type="text" name="est" value="" /> 
        <br/><br/>
        <input type="submit" value="Registre Nuevo Pedido" /> 
    </form>
    <?php
}
?>
a la espera de su ayuda saludos.

Etiquetas: eclipse, java, json, mysql, netbeans
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:42.