Search in sources :

Example 61 with JSONArray

use of net.sf.json.JSONArray in project cachecloud by sohutv.

the class AppController method assembleAppStatsJson.

/**
 * AppStats列表组装成json串
 */
private String assembleAppStatsJson(List<AppStats> appStats, String statName) {
    if (appStats == null || appStats.isEmpty()) {
        return "[]";
    }
    List<SimpleChartData> list = new ArrayList<SimpleChartData>();
    for (AppStats stat : appStats) {
        try {
            SimpleChartData chartData = SimpleChartData.getFromAppStats(stat, statName);
            list.add(chartData);
        } catch (ParseException e) {
            logger.info(e.getMessage(), e);
        }
    }
    JSONArray jsonArray = JSONArray.fromObject(list);
    return jsonArray.toString();
}
Also used : ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) SimpleChartData(com.sohu.cache.web.chart.model.SimpleChartData) ParseException(java.text.ParseException)

Example 62 with JSONArray

use of net.sf.json.JSONArray in project wechat by dllwh.

the class XdailiProxyHelper method getFreeIps.

/**
 * @方法描述: 获取免费代理IP
 * @param page
 * @return
 * @throws Exception
 */
public static String getFreeIps(int page) throws Exception {
    if (page < 1) {
        page = 1;
    }
    getFreeIpListUrl = String.format(getFreeIpListUrl, page);
    String result = HttpURLConnHelper.getInstance().sendGetRequest(getFreeIpListUrl);
    JSONObject _result = JSONObject.fromObject(result);
    List<Map<String, Object>> resultList = Lists.newArrayList();
    if (_result.has("ERRORCODE")) {
        if ("0".equals(_result.getString("ERRORCODE"))) {
            String childResult = _result.getString("RESULT");
            if (StringUtils.isNoneBlank(childResult)) {
                JSONObject _cResult = JSONObject.fromObject(childResult);
                JSONArray _Jarray = JSONArray.fromObject(_cResult.getString("rows"));
                JSONObject job = null;
                ProxyPool proxyIP = null;
                for (int i = 0; i < _Jarray.size(); i++) {
                    try {
                        job = _Jarray.getJSONObject(i);
                        proxyIP = new ProxyPool();
                        proxyIP.setIp(job.getString("ip"));
                        proxyIP.setPort(Integer.valueOf(job.getString("port")));
                        String[] position = job.getString("position").split(" ");
                        proxyIP.setPosition(position[0]);
                        proxyIP.setIsp(position[1]);
                        proxyIP.setProtocolType(job.getString("type").split("/"));
                        resultList.add(MapUtilHelper.beanToMap(proxyIP));
                    } catch (Exception e) {
                        logger.error(e);
                    }
                    System.err.println();
                }
            }
        }
    }
    return JsonMapper.toJsonString(resultList);
}
Also used : JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) ProxyPool(com.cdeledu.crawler.SocialNetwork.proxy.entity.ProxyPool) Map(java.util.Map)

Example 63 with JSONArray

use of net.sf.json.JSONArray in project phabricator-jenkins-plugin by uber.

the class Differential method getChangedFiles.

/**
 * Get the list of changed files in the diff.
 *
 * @return the list of changed files in the diff.
 */
public Set<String> getChangedFiles() {
    Set<String> changedFiles = new HashSet<String>();
    JSONArray changes = rawJSON.getJSONArray("changes");
    for (int i = 0; i < changes.size(); i++) {
        JSONObject change = changes.getJSONObject(i);
        String file = (String) change.get("currentPath");
        if (file != null) {
            changedFiles.add(file);
        }
    }
    return changedFiles;
}
Also used : JSONObject(net.sf.json.JSONObject) JSONArray(net.sf.json.JSONArray) HashSet(java.util.HashSet)

Example 64 with JSONArray

use of net.sf.json.JSONArray in project nodejs-plugin by jenkinsci.

the class InstallerPathResolversTest method data.

@Parameterized.Parameters(name = "{index}: {3}")
public static Collection<Object[]> data() throws Exception {
    Collection<Object[]> testPossibleParams = new ArrayList<Object[]>();
    try (InputStream is = InstallerPathResolversTest.class.getResourceAsStream("expectedURLs.txt")) {
        expectedURLs = new TreeSet<>(IOUtils.readLines(is));
    }
    String installablesJSONStr = Resources.toString(Resources.getResource("updates/jenkins.plugins.nodejs.tools.NodeJSInstaller.json"), Charsets.UTF_8);
    JSONArray installables = JSONObject.fromObject(installablesJSONStr).getJSONArray("list");
    for (int i = 0; i < installables.size(); i++) {
        DownloadFromUrlInstaller.Installable installable = (DownloadFromUrlInstaller.Installable) installables.getJSONObject(i).toBean(DownloadFromUrlInstaller.Installable.class);
        // structure is not handled
        if (InstallerPathResolver.Factory.isVersionBlacklisted(installable.id)) {
            continue;
        }
        for (Platform platform : Platform.values()) {
            for (CPU cpu : CPU.values()) {
                if (cpu.name().startsWith("arm") && platform != Platform.LINUX) {
                    // arm are only supported on linux
                    continue;
                }
                if (platform == Platform.AIX && !cpu.name().equals("ppc64")) {
                    // AIX only supports ppc64
                    continue;
                }
                String testName = String.format("version=%s,cpu=%s,platform=%s", installable.id, cpu.name(), platform.name());
                testPossibleParams.add(new Object[] { installable, platform, cpu, testName });
            }
        }
    }
    return testPossibleParams;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) JSONArray(net.sf.json.JSONArray) DownloadFromUrlInstaller(hudson.tools.DownloadFromUrlInstaller) JSONObject(net.sf.json.JSONObject)

Example 65 with JSONArray

use of net.sf.json.JSONArray in project camel by apache.

the class XmlJsonDataFormatTest method testXmlArraysToJson.

@Test
public void testXmlArraysToJson() throws Exception {
    MockEndpoint mockJSON = getMockEndpoint("mock:jsonInlineOptionsArray");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);
    Object json = template.requestBody("direct:marshalInlineOptionsArray", "<ar><el>1</el><el>2</el><el>3</el><el>4</el></ar>");
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONArray array = (JSONArray) JSONSerializer.toJSON(jsonString);
    assertTrue("Expected a JSON array with string elements: 1, 2, 3, 4", array.containsAll(Arrays.asList("1", "2", "3", "4")));
    mockJSON.assertIsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) JSONArray(net.sf.json.JSONArray) JSONObject(net.sf.json.JSONObject) Test(org.junit.Test)

Aggregations

JSONArray (net.sf.json.JSONArray)144 JSONObject (net.sf.json.JSONObject)109 ArrayList (java.util.ArrayList)31 IOException (java.io.IOException)22 HashMap (java.util.HashMap)20 File (java.io.File)16 Test (org.junit.Test)15 JSON (net.sf.json.JSON)14 Map (java.util.Map)12 JsonConfig (net.sf.json.JsonConfig)10 URISyntaxException (java.net.URISyntaxException)9 URL (java.net.URL)9 URI (java.net.URI)8 SimpleChartData (com.sohu.cache.web.chart.model.SimpleChartData)6 Date (java.util.Date)6 CheckedServiceException (com.bc.pmpheep.service.exception.CheckedServiceException)5 OutputStream (java.io.OutputStream)5 List (java.util.List)5 CAFunctorFactory (edu.uiuc.ncsa.myproxy.oa4mp.oauth2.claims.CAFunctorFactory)4 OA2Client (edu.uiuc.ncsa.security.oauth_2_0.OA2Client)4