private String getJsonStr(List<String> jsonKeyList, String[] values){
    String jsonStr = "{";
    if (jsonKeyList == null){
      Log.getInstance().printError(this.getClass().getName(), "拼写json出错,json对象属性名list为空");
      return null;
    }
    if (values == null){
      Log.getInstance().printError(this.getClass().getName(), "拼写json出错,json对象属性值数组为空");
      return null;
    }
    if (jsonKeyList.size() != values.length){
      Log.getInstance().printError(this.getClass().getName(), "拼写json出错,json对象属性名和值个数不对应");
      return null;
    }
    if (values.length < 2){
      Log.getInstance().printError(this.getClass().getName(), "拼写json出错,json对象属性值个数小于2");
      return null;
    }
    if (jsonKeyList.size() <= 0){
      jsonStr += " \"groupID\":\"-1\" ";
    }
    for (int i = 0; i < jsonKeyList.size(); i++){
      // json属性名为空
      if (!StringUtils.isEmpty(jsonKeyList.get(i))){
        Log.getInstance().printError(this.getClass().getName(), "拼写json出错,json对象属性名为空");
        return null;
      }
      if (!StringUtils.isEmpty(values[i])){
        // 如果是最后一项
        if (i == values.length - 1){
          // 如果前一项是-1很正常
          if ("-1".equals(values[values.length - 2])){
            values[values.length - 1] = "同步通讯录组";
          }else{
            return null;
          }
        }else{
          Log.getInstance().printError(this.getClass().getName(), "拼写json出错,json对象属性值为空");
          return null;
        }
      }
      jsonStr += "\"" + jsonKeyList.get(i) + "\":\"" + values[i] + "\"";
      if (i < jsonKeyList.size() - 1){
        jsonStr += ",";
      }
    }
    jsonStr += "}";
    Log.getInstance().printInfo(this.getClass().getName(), jsonStr);
    return jsonStr;
  }

 

posted on 2017-01-09 12:22  悲伤穿透眼眸  阅读(1310)  评论(0编辑  收藏  举报