JSON对象中的值未被访问

时间:2015-10-03 00:33:18

标签: android null jsonobject

我有JSON对象descripcionelement.send_keys(descripciontext) 看起来像contacts在我的代码中,我抓住{"email":"Mark@HookahStationBCS.com","phone":"+19796918899"}键并且能够获得它的值,但是当我打印出phone时1}}值表示它为空,在我下面的代码中它实际上并没有通过终止案例。有谁知道为什么?

email

2 个答案:

答案 0 :(得分:1)

我认为您的代码应该是这样的:

if (nextActivityObject.getJSONObject("contacts") != null){

    Log.d("NEXT ACTIVITY OBJECT NOT EMPTY", "NOT EMPTY");
    contacts = nextActivityObject.getJSONObject("contacts");

    if(contacts.getString("phone") != null && contacts.getString("email") != null){

       phone = contacts.getString("phone");
       email = contacts.getString("email");

       intent.putExtra("phone",phone);
       intent.putExtra("email",email);

     } 
     else if (contacts.getString("phone") != null){

              phone= contacts.getString("phone");
              intent.putExtra("phone", phone);
     }
     else if (contacts.getString("email") != null){

              email = contacts.getString("email");
              intent.putExtra("email", email);
     }

}

答案 1 :(得分:0)

你有一个elseif条件..你必须有2条件条件。我几乎都在说上一张海报所说的内容,只是用不同的方式写出来。