は、私のコードは次のようである:JSON - 私はJSONエンコードでログインフォームを行ってきたログインフォーム
public void onClick(View v) {
if(v==login){
login();
}
}
public void login(){
String url_select = "http://ipadress/select.php";
HttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url_select);
//parameter
ArrayList<NameValuePair> param = new ArrayList<NameValuePair>();
try {
//add parameter
httpPost.setEntity(new UrlEncodedFormEntity(param));
HttpResponse httpRespose = httpClient.execute(httpPost);
HttpEntity httpEntity = httpRespose.getEntity();
//read content
InputStream in = httpEntity.getContent();
BufferedReader read = new BufferedReader(new InputStreamReader(in));
String content = "";
String line = "";
while((line = read.readLine())!=null){
content += line;
}
Log.d("ADBUG", "content: "+content);
//json
if(!content.equals("null")){
try {
JSONArray jArr = new JSONArray(content);
String uname="";
String passw="";
String idx="";
for(int i=0;i<jArr.length();i++){
JSONObject jObj = jArr.getJSONObject(i);
String id = jObj.getString("_id");
String username = jObj.getString("username");
String password = jObj.getString("password");
idx += id+"\n";
uname += username+"\n";
passw += password+"\n";
}
if(user.getText().toString().equals(uname) && pass.getText().toString().equals(passw)){
Intent a;
a = new Intent(this, WelcomeMenu.class);
startActivity(a);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
Toast.makeText(this, "Error", Toast.LENGTH_LONG).show();
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
select.php:
<?php
include_once("koneksi.php");
$number_id= $_REQUEST['number_id'];
if($nomor_id){
$sqlString = "select * from login where _id=$number_id";
}else{
$sqlString = "select * from login";
}
$rs = mysql_query($sqlString);
if($rs){
while($objRs = mysql_fetch_assoc($rs)){
$output[] = $objRs;
}
echo json_encode($output);
}
mysql_close();
?>
問題は、私はできないですログイン、私はすでに私のSQLにユーザー名とパスワードを挿入されている、buat私はログインできない、誰も私を助けることができますか?ありがとうございます。
ここでログインしていますか?サーバー側かモバイル?ログインに成功するとサーバーから何かが戻ってきますか? –
私はモバイルからログインしたいと思う、サーバーはちょうどログインのために使用されるユーザー名とパスワードを保持する、あなたはそれを行う方法を知っていますか? – Handy