Java Code Examples for com.alibaba.fastjson.JSONArray#toArray()

The following examples show how to use com.alibaba.fastjson.JSONArray#toArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IHttpServletRequestWrapper.java    From common-project with Apache License 2.0 6 votes vote down vote up
public void addParameter(String name , Object value) {//增加参数
    if(value == null) {
        return;
    }
    if(value instanceof String[]) {
        params.put(name , (String[])value);
    }else if(value instanceof String) {
        params.put(name , new String[] {(String)value});
    }else if (value instanceof JSONArray){
        JSONArray jsonArray = (JSONArray) value;
        Object[] objects = jsonArray.toArray();
        String[] values = new String[jsonArray.size()];
        for (int i=0;i<values.length;i++){
            values[i]=objects[i].toString();
        }
        params.put(name,values);
    }else {
        params.put(name , new String[] {String.valueOf(value)});
    }
}
 
Example 2
Source File: JsonUtils.java    From litchi with Apache License 2.0 5 votes vote down vote up
public static String[] readStringArray(JSONObject jsonObject, String item) {
    JSONArray basePackagesArray = jsonObject.getJSONArray(item);
    String[] value = new String[basePackagesArray.size()];
    basePackagesArray.toArray(value);

    return value;
}
 
Example 3
Source File: HBaseUtil.java    From DataLink with Apache License 2.0 5 votes vote down vote up
public static List<HBaseRange> generateHBaseSplitInfo(MediaSourceInfo info, String tableName, int splitCount) {
    checkHbase(info);
    HBaseMediaSrcParameter parameter = info.getParameterObj();
    long zkId = parameter.getZkMediaSourceId();
    String znode = parameter.getZnodeParent();
    MediaSourceInfo zkInfo = dao.findMediaSourceById(zkId);
    checkZookeepr(zkInfo);
    ZkMediaSrcParameter zkParameter = zkInfo.getParameterObj();

    HBaseParameterVO vo = new HBaseParameterVO();
    vo.setTableName(tableName);
    vo.setZkAddress(zkParameter.getServers());
    vo.setPort(zkParameter.parsePort() + "");
    vo.setZnode(parameter.getZnodeParent());
    vo.setSplitCount(splitCount);
    vo.setHbaseParameter(parameter);
    String json = execute(vo, GENERATE_SPLIT_INFO);
    Map<String, Object> map = JSONObject.parseObject(json, Map.class);
    JSONArray array = (JSONArray) map.get("range");
    Object[] obj_arr = array.toArray();
    List<HBaseRange> list = new ArrayList<>();
    for (Object o : obj_arr) {
        String str = JSONObject.toJSONString(o);
        HBaseRange hr = JSONObject.parseObject(str, HBaseRange.class);
        list.add(hr);
    }
    return list;
}
 
Example 4
Source File: TagsComponent.java    From weixin4j with Apache License 2.0 5 votes vote down vote up
/**
 * 获取用户身上的标签列表
 *
 * @param openid 粉丝OpenId
 * @return 公众号标签ID集合
 * @throws org.weixin4j.WeixinException 微信操作异常
 */
public Integer[] getIdList(String openid) throws WeixinException {
    //创建请求对象
    HttpsClient http = new HttpsClient();
    //调用获取用户身上的标签列表接口
    Response res = http.get("https://api.weixin.qq.com/cgi-bin/tags/getidlist?access_token=" + weixin.getToken().getAccess_token());
    //根据请求结果判定,是否验证成功
    JSONObject jsonObj = res.asJSONObject();
    //成功返回如下JSON:
    //{"tagid_list":[134,2]}
    if (jsonObj != null) {
        if (Configuration.isDebug()) {
            System.out.println("获取/tags/getidlist返回json:" + jsonObj.toString());
        }
        Object errcode = jsonObj.get("errcode");
        if (errcode != null && !errcode.toString().equals("0")) {
            //返回异常信息
            throw new WeixinException(getCause(jsonObj.getIntValue("errcode")));
        } else {
            JSONArray tags = jsonObj.getJSONArray("tagid_list");
            if (tags != null) {
                return tags.toArray(new Integer[]{});
            }
        }
    }
    return null;
}
 
Example 5
Source File: AppVariantContext.java    From atlas with Apache License 2.0 5 votes vote down vote up
public Map<String, String> getBaseUnitTagMap() throws IOException {
    Map<String, String> tagMap = new HashMap<>();
    if (null != this.apContext.getApExploredFolder()
            && this.apContext.getApExploredFolder().exists()) {
        File file = new File(this.apContext.getApExploredFolder(), "atlasFrameworkProperties.json");
        if (file.exists()) {
            JSONObject jsonObject = (JSONObject) JSON.parse(org.apache.commons.io.FileUtils.readFileToString(file));
            JSONArray jsonArray = jsonObject.getJSONArray("bundleInfo");
            for (JSONObject obj : jsonArray.toArray(new JSONObject[0])) {
                tagMap.put(obj.getString("pkgName"), obj.getString("unique_tag"));
            }
        }
    }
    return tagMap;
}
 
Example 6
Source File: TagsComponent.java    From weixin4j with Apache License 2.0 4 votes vote down vote up
/**
 * 获取公众号的黑名单openids列表
 *
 * @param openid 开始粉丝OpenId(首次传空)
 * @return 黑名单列表
 * @throws org.weixin4j.WeixinException 微信操作异常
 * @since 0.1.4
 */
public String[] membersGetBlackList(String openid) throws WeixinException {
    //创建请求对象
    HttpsClient http = new HttpsClient();
    //封装请求参数
    JSONObject postParam = new JSONObject();
    postParam.put("begin_openid", openid);
    //调用获取用户身上的标签列表接口
    Response res = http.post("https://api.weixin.qq.com/cgi-bin/tags/members/getblacklist?access_token=" + weixin.getToken().getAccess_token(), postParam);
    //根据请求结果判定,是否验证成功
    JSONObject jsonObj = res.asJSONObject();
    //成功返回如下JSON:
    //{
    // "total":23000,
    // "count":10000,
    // "data":{"
    //    openid":[
    //       "OPENID1",
    //       "OPENID2",
    //       ...,
    //       "OPENID10000"
    //    ]
    //  },
    //  "next_openid":"OPENID10000"
    //}
    if (jsonObj != null) {
        if (Configuration.isDebug()) {
            System.out.println("获取/tags/members/getblacklist返回json:" + jsonObj.toString());
        }
        Object errcode = jsonObj.get("errcode");
        if (errcode != null && !errcode.toString().equals("0")) {
            //返回异常信息
            throw new WeixinException(getCause(jsonObj.getIntValue("errcode")));
        } else {
            JSONObject data = jsonObj.getJSONObject("data");
            if (data != null) {
                //获取openid集合
                JSONArray arrays = data.getJSONArray("openid");
                if (openid != null) {
                    String[] openids = arrays.toArray(new String[]{});
                    //根据openid查询用户信息
                    return openids;
                }
            }
        }
    }
    return null;
}
 
Example 7
Source File: DiffBundleInfoTask.java    From atlas with Apache License 2.0 4 votes vote down vote up
private Set<ArtifactBundleInfo> getArtifactBundleInfo(DependencyDiff dependencyDiff,
                                                      File mainfestFile,
                                                      File apDir) throws IOException, DocumentException {

    Set<ArtifactBundleInfo> artifactBundleInfos = new HashSet<ArtifactBundleInfo>();
    if (null == apDir) {
        throw new GradleException("No Ap dependency found!");
    }
    File apManifest = new File(apDir, "AndroidManifest.xml");
    String apVersion = null;
    try {
        apVersion = ManifestFileUtils.getVersionName(apManifest);
    } catch (Exception e) {
        throw new GradleException(e.getMessage(), e);
    }

    Map<String,String> tagMap = new HashMap<>();
    JSONObject jsonObject = (JSONObject)JSON.parse(FileUtils.readFileToString(new File(apDir, "atlasFrameworkProperties.json")));
    JSONArray jsonArray = jsonObject.getJSONArray("bundleInfo");
    for (JSONObject obj : jsonArray.toArray(new JSONObject[0])){
        tagMap.put(obj.getString("pkgName"), obj.getString("unique_tag"));
    }



    // 2. Add your own bundle
    AtlasDependencyTree atlasDependencyTree = AtlasBuildContext.androidDependencyTrees.get(
            appVariantOutputContext.getVariantContext().
                    getVariantConfiguration().getFullName());

    List<AwbBundle>modifyMbundles = new ArrayList<>();
    for (AwbBundle awbBundle : atlasDependencyTree.getAwbBundles()) {
        BundleInfo bundleInfo = awbBundle.bundleInfo;
        ArtifactBundleInfo awbBundleInfo = new ArtifactBundleInfo();
        awbBundleInfo.setMainBundle(false);
        awbBundleInfo.setDependency(newDependency(bundleInfo.getDependency(),appVariantOutputContext.getVariantContext()));
        awbBundleInfo.setPkgName(bundleInfo.getPkgName());
        awbBundleInfo.setApplicationName(bundleInfo.getApplicationName());
        awbBundleInfo.setArtifactId(awbBundle.getResolvedCoordinates().getArtifactId());
        awbBundleInfo.setName(bundleInfo.getName());
        //History bundle's tag todo
        awbBundleInfo.setSrcUnitTag(tagMap.get(bundleInfo.getPkgName()));
        awbBundleInfo.setUnitTag(bundleInfo.getUnique_tag());
        String version = bundleInfo.getVersion();
        if (version.indexOf("@") > 0) {
            String[] arr = version.split("@");
            version = arr[arr.length - 1];
        }
        awbBundleInfo.setVersion(version);

        //TODO
        bundleInfo.getUnique_tag();

        String libBundleName = getBundleName(awbBundle);
        if (dependencyDiff.getAwbDiffs().contains(libBundleName)) {
            if (dependencyDiff.getNewAwbs().contains(libBundleName)) {
                awbBundleInfo.setDiffType(DiffType.ADD);
            } else {
                awbBundleInfo.setDiffType(DiffType.MODIFY);
            }
        } else {
            awbBundleInfo.setDiffType(DiffType.NONE);
        }

        if (awbBundle.isMBundle) {
            if (awbBundleInfo.getDiffType() == DiffType.ADD || awbBundleInfo.getDiffType() == DiffType.MODIFY) {
                modifyMbundles.add(awbBundle);
            }
            continue;
        }

        artifactBundleInfos.add(awbBundleInfo);
    }

    // 1. First add the main bundle
    ArtifactBundleInfo mainBundleInfo = getMainArtifactBundInfo(mainfestFile);
    mainBundleInfo.setBaseVersion(apVersion);
    mainBundleInfo.setMainBundle(true);
    mainBundleInfo.setVersion(appVariantOutputContext.getVariantContext()
            .getVariantConfiguration()
            .getVersionName());
    if (dependencyDiff.getMainDexDiffs().size() > 0 || modifyMbundles.size() > 0) {
        mainBundleInfo.setDiffType(DiffType.MODIFY);
    } else {
        mainBundleInfo.setDiffType(DiffType.NONE);
    }

    mainBundleInfo.setSrcUnitTag(jsonObject.getString("unit_tag"));
    mainBundleInfo.setUnitTag(appVariantOutputContext.getVariantContext().unit_tag);

    artifactBundleInfos.add(mainBundleInfo);

    return artifactBundleInfos;
}