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();
}
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);
}
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;
}
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;
}
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();
}
Aggregations