当我的数据存储区中的companyTwo值为空白时,我得到以下信息:
09-09 15:13:52.927: W/System.err(31091): org.json.JSONException: No value for companyTwo
假设我只能从数据存储区中提取数据,而不发布填充值,这将是处理此问题的好方法吗?
private static final String TAG_COMPANY ="company";
private static final String TAG_OTHERCOMPANY ="companyTwo";
String company1 = jsonObj1.getString(TAG_COMPANY);
String othercompany1 = jsonObj1.getString(TAG_OTHERCOMPANY);
最佳答案
try
{
String company1 = jsonObj1.getString(TAG_COMPANY);
}
catch(Exception ex)
{
// do whatever you want
}
或者,您可以这样做
String company1 = String.valueOf(jsonObj1.optString(TAG_COMPANY));