加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

【解决问题】解析服务器端返回的JSONObject对象

发布时间:2020-12-16 19:29:03 所属栏目:百科 来源:网络整理
导读:public ListObject[] syncSVR(MapString,String info){JSONArray jsonListObjs = null;//ListObject[]JSONArray jsonObjs = null;//Object[]JSONArray jsonObjectsList = null; // Object[1] == ListObjectListObject[] result = null;Object[] objs = new O

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>

转换的代码,如上所示。

重点看转换的过程即可,其他可以忽略。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读