[
{
"vid": "45",
"name": "hello",
"description": "hello",
"help": "hello",
"relations": "1",
"hierarchy": "1",
"multiple": "1",
"required": "0",
"tags": "1",
"module": "taxonomy",
"weight": "7",
"nodes": {
"hidrupal": "hidrupal",
"page": "page",
"recipee": "recipee",
"story": "story"
},
"uri": "http://andrd.yarrait.com/drupal6/android/vocabulary/45"
},
{
"vid": "48",
"name": "sample",
"description": "asldfawi iawbfuiasguda jasbf jasfujad jashbdfajsdgawidba kjascbi9wa jhasbjabcuasv askjh bw ajs bjsbjda jsawioabfscja awjdbfuwga ajcsjfgjaw ajdfajs fj agfjweu8 ajsfbjw u",
"help": "ajfawyg ahbcoiw ygajc jawhbu bua jagbwjwcwug ua jwsajwiuhcg ha bwujagua jajdwgugd uma jau wyg j h jja hg ug auj gwj",
"relations": "1",
"hierarchy": "1",
"multiple": "1",
"required": "0",
"tags": "1",
"module": "taxonomy",
"weight": "7",
"type": null,
"nodes": [ ],
"uri": "http://andrd.yarrait.com/drupal6/android/vocabulary/48"
}
]
我有2个JSONArray,它有“节点”对象,有时有值,有时有空值,所以如何检查这个“节点”对象是否有空值
我以这种方式尝试。请检查它并告诉我如何解决这个问题 JSONArray
mJSONArray = new JSONArray(response);
for (int i = 0; i < mJSONArray.length(); i++)
{
JSONObject mJSONObject = mJSONArray.getJSONObject(i);
mArrayListName.add(mJSONObject.getString(Constant.VocabularyJsonKey.NAME));
mArrayListvid.add(mJSONObject.getString(Constant.VocabularyJsonKey.VID));
if(!mJSONObject.isNull(Constant.VocabularyJsonKey.CONTENT_TYPE))
{
JSONObject contentTypeJSONObject = mJSONObject.getJSONObject(Constant.VocabularyJsonKey.CONTENT_TYPE);
JSONArray contentTypeJSONArray = contentTypeJSONObject.toJSONArray(contentTypeJSONObject.names());
//for getting content types and set as comma separated string
for (int j = 0; j < contentTypeJSONArray.length(); j++)
{
if(j == contentTypeJSONArray.length()-1)
content_types = content_types.concat(contentTypeJSONArray.getString(j).toString());
else
content_types = content_types.concat(contentTypeJSONArray.getString(j).toString() + ", ");
}
}
mArrayListCtype.add(content_types);
}
当我列出比因为获取节点对象空值时发生错误。错误是 org.json.JSONException:在 org.json.JSONObject.getJSONObject( JSONObject.java:573)