如何获取字符串值JSON解析

时间:2019-04-29 17:07:31

标签: android

如何从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();
        }
    }
}

1 个答案:

答案 0 :(得分:0)

将代码更改为

@Override
public void run() {
if (country.equals(countryKode)) {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
...

这应该有效。