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-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.






0 comentários:
Postar um comentário