com.alibaba.fastjson.JSONArray#toArray ( )源码实例Demo

下面列出了com.alibaba.fastjson.JSONArray#toArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

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)});
    }
}
 
源代码2 项目: litchi   文件: JsonUtils.java
public static String[] readStringArray(JSONObject jsonObject, String item) {
    JSONArray basePackagesArray = jsonObject.getJSONArray(item);
    String[] value = new String[basePackagesArray.size()];
    basePackagesArray.toArray(value);

    return value;
}
 
源代码3 项目: DataLink   文件: HBaseUtil.java
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;
}
 
源代码4 项目: weixin4j   文件: TagsComponent.java
/**
 * 获取用户身上的标签列表
 *
 * @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;
}
 
源代码5 项目: atlas   文件: AppVariantContext.java
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;
}
 
源代码6 项目: weixin4j   文件: TagsComponent.java
/**
 * 获取公众号的黑名单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;
}
 
源代码7 项目: atlas   文件: DiffBundleInfoTask.java
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;
}