android - Value in JSON Object not being accessed -
i have json object contacts
looks {"email":"mark@hookahstationbcs.com","phone":"+19796918899"}
in code grab phone
key , able it's value, when print out email
value says it's null, , in code below doesn't pass termination case. know why?
if(nextactivityobject.getjsonobject("contacts") != null){ log.d("next activity object not empty", "not empty"); contacts = nextactivityobject.getjsonobject("contacts"); if(contacts.getstring("phone") != null){ phone = contacts.getstring("phone"); log.d("phone passed", phone.tostring()); intent.putextra("phone",phone); } else if(contacts.getstring("email") != null){ email = contacts.getstring("email"); log.d("this email pass", email.tostring()); intent.putextra("email", email); } }
i think code should this:
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); }
}
Comments
Post a Comment