gpt4 book ai didi

php - 我怎么能在我的应用程序中使用 json?

转载 作者:行者123 更新时间:2023-11-29 00:35:25 26 4
gpt4 key购买 nike

我已经为具有登录页面的用户创建了一个项目。我需要使用带有 PHP 的 jSON 登录应用程序。

public class login extends Activity {
EditText e1, e2;
Button bt1, bt2;
String s1, s2, Authendication;
String S1,S2,u1[],p1[];
String Uname;
int i=0,j=0;
Resources res;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login);
e1 = (EditText) findViewById(R.id.userName);
e2 = (EditText) findViewById(R.id.pwd);
bt1 = (Button) findViewById(R.id.btLogin);
bt2 = (Button) findViewById(R.id.btExit);
res = getResources();

DBConnect dc=new DBConnect(this);
try {
SQLiteDatabase sqdb = db.getReadableDatabase();
Cursor c = sqdb.rawQuery("select UserID,password from User", null);
if (c != null) {
if (c.moveToFirst()) {
do {
S1=S1+","+c.getString(c.getColumnIndex("UserID"));
S2=S2+","+c.getString(c.getColumnIndex("password"));
i++;
} while (c.moveToNext());
}
}
} catch (Exception e) {
Toast.makeText(login.this, e.toString(), Toast.LENGTH_LONG).show();
}
bt1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
int s = 0;
String regex = "(,)";
u1 = S1.split(regex);
p1 = S2.split(regex);
s1 = e1.getText().toString();
s2 = e2.getText().toString();
for (j = 0; j <= i; j++)
{
if((s1.equals(u1[j])) && (s2.equals(p1[j])))
{
s=1;
Toast.makeText(login.this, "Login Successfully",
Toast.LENGTH_LONG).show();
Intent i1 = new Intent("My Next Screen");
startActivity(i1);
}
}
if(s == 0){
Toast.makeText(login.this, "Login fail",
Toast.LENGTH_LONG).show();
}

}
});
bt2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
e2.setText("");
finish();
}
});
}
}

我的 Xml 文件有 2 个编辑框和 2 个按钮。我可以使用 PHP for Server Database with JSON 执行这些选项吗?

帮我实现这个。

最佳答案

使用以下方法进行编码......

 DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();

也可以使用以下链接..

Android PHP connection through Java

关于php - 我怎么能在我的应用程序中使用 json?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12972285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com