0
我是JSON的新手。請任何人給一個示例代碼用於獲取JSON值... 當我點擊登錄按鈕,我想獲得用戶令牌valules從Json的object..please幫助我..我沒有得到RSS feed值..我認爲獲取Feed值時出錯
這裏是我的代碼..
謝謝你在先進..
public void onClick(View v) {
switch(v.getId()){
case R.id.btnLogin:
txtUserName=(EditText)this.findViewById(R.id.txtUname);
txtPassword=(EditText)this.findViewById(R.id.txtPwd);
String uname = txtUserName.getText().toString();
String pass = txtPassword.getText().toString();
if(uname.equals("") || uname == null){
Toast.makeText(getApplicationContext(), "Username Empty", Toast.LENGTH_SHORT).show();
}else if(pass.equals("") || pass == null){
Toast.makeText(getApplicationContext(), "Password Empty", Toast.LENGTH_SHORT).show();
}else{
boolean validLogin = validateLogin(uname, pass, Loginpage.this);
if(validLogin){
}
}
break;
case R.id.btnCancel:
Intent i = new Intent(Loginpage.this,Loginpage.class);
startActivity(i);
//finish();
break;
}
}
private boolean validateLogin(String uname, String pass, Loginpage loginpage) {
System.out.println("UserToken...");
loginuser();
Intent intent = new Intent(Loginpage.this, Main.class);
intent.putExtra("tokenNumber", token);
startActivity(intent);
return true;
}
private void loginuser() {
// TODO Auto-generated method stub
JSONObject json = JSONfunctions.getJSONfromURL("http://xxx.xxx.x.xxx/my url link...");
token = null;
try {
token = json.getString("UserToken");
} catch (JSONException e) {
e.printStackTrace();
}
System.out.println("UserToken:"+token);
}