[
{
"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在於,它具有「節點」對象,有時有值和有時候具有空,因此如何檢查這個「節點」對象是否有空值我已JSON在存在一個其它JSON對象所以如何檢查第二JSON對象爲空
我試試這樣。請檢查,並告訴我如何解決這個問題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.JSONArray的節點上的值[]無法在org.json.JSONObject的org.json.JSON.typeMismatch(JSON.java:96)處轉換爲JSONObject。 getJSONObject(JSONObject.java:573)
你試過了嗎? 'OuterObject.innerObject === null'。在你的case object [0] .nodes中=== null –
JSONObject jsonObject; jsonObject.isNull(「name」); – Pasha