Problème données JSON Object
Bonjour,
Je récupère des données d'une base de données pour une authentification de compte. Mais si j'ai plusieurs clients dans ma liste, les tests ne s'effectuent que pour le dernier.
J'aimerai récupérer uniquement la ligne correspondant à l'adresse email entrée dans l'editText correspondant.
Le code vous donnera peut-être une idée plus claire de mon problème :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| private class JSONParse extends AsyncTask<String, String, JSONArray> {
private ProgressDialog pDialog;
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected JSONArray doInBackground(String... args) {
JSONParser jParser = new JSONParser();
// Getting JSON from URL
JSONArray json = jParser.getJSONFromUrl(urlauthentification);
return json;
}
@Override
protected void onPostExecute(JSONArray json) {
try {
// On récupère le tableau JSON de l'URL
for(int i = 0; i < json.length(); i++){
JSONObject c = json.getJSONObject(i);
// On stocke les valeurs JSON dans une variable
prenom = c.getString(TAG_PRENOM);
Cemail = c.getString(TAG_EMAIL);
password = c.getString(TAG_PASS);
Connexion.setOnClickListener(new OnClickListener() {
...... |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
public class JSONParser {
static InputStream is = null;
static JSONArray jObj = null;
static String json = "";
// constructor
public JSONParser() {
}
public JSONArray getJSONFromUrl(String url) {
// Making HTTP request
try {
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(
is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONArray(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
} |
J'ai essayé dans ma requête SQL de ne récupérer que les informations d'un client selon l'adresse email présent dans un EditText
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| <?php
include ('JSON.php');
// create a new instance of Services_JSON
$json = new Services_JSON();
mysql_connect("sql.free.fr","xxxxx","xxxxxx");
mysql_select_db("xxxxx");
$sql=mysql_query("select Prenom,Email,Pass from tclient WHERE Email like '".$_REQUEST['Email']."%'");
while($row=mysql_fetch_assoc($sql))
$output[] = ($row);
echo $json->encode($output);
mysql_close();
?> |
J'ai essayé différentes boucle while mais sans résultat.