public List<Object[]> syncSVR(Map<String,String> info){
JSONArray jsonListObjs = null;//List<Object[]>
JSONArray jsonObjs = null;//Object[]
JSONArray jsonObjectsList = null; // Object[1] == List<Object>
List<Object[]> result = null;
Object[] objs = new Object[2];
Object[] subObjs = null;
String str = null;
JSONObject jsonObject //
= HttpUtil.doPost(this.getServerURL(HttpUtil.HttpFunction.syncSVR),info);
int status = SVRResult.SVR_SERVER_NOT_RESPOND ;//若JSONObject为null则返回SVR_SERVER_NOT_RESPOND
try {
if(jsonObject !=null){
Log.i(this.getClass().toString(),jsonObject.get("serverMessage").toString());
status = Integer.parseInt(jsonObject.get("serverMessage").toString());
if( status== SVRResult.SVR_OK ){
jsonListObjs = jsonObject.getJSONArray("syncSVR");
result = new ArrayList<Object[]>();
for( int i = 0 ; i < jsonListObjs.length() ; i ++ ) {
//取出
jsonObjs = jsonListObjs.getJSONArray(i);
for( int j = 0 ; j < jsonObjs.length() ; j ++ ) {
//取出
str = jsonObjs.getString(0);
//放置
objs[0] = str ;
//取出
jsonObjectsList = jsonObjs.getJSONArray(1);
subObjs = new Object[jsonObjectsList.length()];
for( int k = 0 ; k < jsonObjectsList.length() ; k ++ ) {
// 放置
subObjs[k] = jsonObjectsList.get(k);
}
//放置
objs[1] = subObjs;
}
//放置
result.add(objs);
}
}
} else {
return result;
}
} catch (Exception e) {
e.printStackTrace();
Log.i("心跳异常",String.valueOf(status));
}
return result;
}
我就举一个例子,服务器返回的值的数据结构是:
List<Object[]> Objectp[0] 是一个String,Object[1]是一个LIst<Object>
转换的代码,如上所示。
重点看转换的过程即可,其他可以忽略。