標籤:span 判斷 func ++ json var instance ons lan
/** * 擷取json資料中所有key */function fetchResponseInfo(responseInfo){ //判斷是否為空白 if((!responseInfo || responseInfo.length <= 0)) { return; } //擷取model var jsonCon = jQuery.parseJSON(responseInfo).model; if(!jsonCon){ return; } //擷取所有key var keyArr; if(jsonCon instanceof Array){ //1-JSONArray if(jsonCon.length <= 0){ return; } var arrOb = jsonCon[0]; keyArr = Object.keys(arrOb); }else if(jsonCon instanceof Object){ //2-JSONObject keyArr = Object.keys(jsonCon); }else{ //3-Other return; } if(!keyArr || keyArr.length <= 0){ return; } //組裝數組 var temOb; var lang = "java.lang.String"; var description = ""; var resArr = new Array(); for(i = 0; i < keyArr.length; i ++){ temOb = new Object(); temOb.param = keyArr[i]; temOb.lang = lang; temOb.description = description; resArr[i] = temOb; } return resArr; }
擷取json資料中所有key集合