Tecnologia do Blogger.
RSS

Re: [androidbrasil-dev] Não receber o dados enviado do android para o web service json

Guilherme, obrigado pela dica, mas será necessário alterar alguma parte do código JAVA ? 

Em sexta-feira, 17 de julho de 2015 00:36:36 UTC-3, Guilherme Lima Pereira escreveu:
Olá,

Recentemente fiz um projeto com angular + php. Dê uma olhada se esse php aqui lhe ajuda:


Guilherme Lima Pereira

On Thu, Jul 16, 2015 at 11:39 PM, Raphael Coelho <rapha...@gmail.com> wrote:
Olá pessoal desde já agradeço a ajuda, estou com um probleminha. Vamos lá, tenho um aplicação que consulta através de um web service JSON se existe registro no banco. No android envio o objeto JSON porém não consigo pegar os valores no PHP . 

arquivo php 

<?php include('connecition.php');?>
<?php
$jsonString = $_POST['json'];

echo $jsonString ;

$jobj = json_encode($jsonString);


echo $jobj ;


$senha = $jobj{'senha'};   //A VARIAVEL SENHA FICA NULA
$email = $jobj{"usuario"}; //A VARIAVEL SENHA FICA NULA

echo  $email;
echo  $senha;


$sql = "SELECT email, senha FROM TB_USUARIO WHERE email = '$email' AND senha = '$senha';";

echo $sql;

$query= mysqli_query($connection,$sql) or die(mysql_error());
$qtda= mysqli_num_rows($query);

if ($qtda == 0){
$json = false;
echo json_encode($json);
}else{
$json = true;
echo json_encode($json);
}

CODIGO JAVA

public boolean verificaUsuarioWebService(String usuario, String senha){
JSONObject jsonUsuario = new JSONObject();
JSONObject json = new JSONObject();
String respostaWeb = null;
try{
jsonUsuario.put("usuario", usuario);
jsonUsuario.put("senha", senha);
json.put("usuarios",jsonUsuario);
HttpClient client = new DefaultHttpClient();
HttpResponse response;
try{
HttpPost post = new HttpPost("http://gjpc.zz.mu/webConsultaUsuario.php");
List<NameValuePair> nVP = new ArrayList<NameValuePair>();  
// nVP.add(new BasicNameValuePair("json", json.toString()));  
nVP.add(new BasicNameValuePair("json", json.toString()));

post.setEntity(new UrlEncodedFormEntity(nVP));
// post.setEntity(new StringEntity(json.toString(), "UTF8"));
response = client.execute(post);

respostaWeb = EntityUtils.toString(response.getEntity());
          Log.i("RESPOSTA WEB USUARIO", respostaWeb);
}catch(Exception e){
}
}catch(Exception e ){
}
if(respostaWeb.equals("true")){
Log.i("RESPOSTA WEB USUARIO", "usuário encontrado");
flagAdm.setValorFlag(1);
BD.atualizarFlagADM(flagAdm);
return true;
}else{
Log.i("RESPOSTA WEB USUARIO", "usuário não encontrado");
flagAdm.setValorFlag(0);
BD.atualizarFlagADM(flagAdm);
return false;
}
}


ERRO NO PHP 
07-16 23:36:19.287: I/RESPOSTA WEB USUARIO(2275): <b>Warning</b>:  Illegal string offset 'senha' 
07-16 23:36:19.287: I/RESPOSTA WEB USUARIO(2275): <b>Warning</b>:  Illegal string offset 'usuario' in 

Poderia ajudar como faço para consiga capturar o valores do JSON?

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Android Brasil - Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to androidbrasil-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

  • Digg
  • Del.icio.us
  • StumbleUpon
  • Reddit
  • RSS

0 comentários:

Postar um comentário