我是JSON的新手。请任何人提供获取JSON值的示例代码...... 当我点击登录按钮,我想从Json对象获取用户令牌值。请帮助我..
这是我的代码..
先谢谢你。
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);
}