如何从json获取字符串值。如果country == countryKode
不起作用。坦克
JSONObject jsonPost = new JSONObject(response.toString());
txtBody.setText(jsonPost.getString("country_name"));
final String country = String.valueOf(jsonPost.get("country_name"));
final String countryKode = "Indonesia";
Handler handler = new Handler();
handler.postDelayed(new
Runnable() {
@Override
public void run () {
if (country == countryKode) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
} else {
Toast.makeText(getApplicationContext(), "Your Not Indonesia", Toast.LENGTH_SHORT).show();
}
}
}
答案 0 :(得分:0)
将代码更改为
@Override
public void run() {
if (country.equals(countryKode)) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
...
这应该有效。