本文整理了Java中net.sf.json.JSONArray.toArray()
方法的一些代码示例,展示了JSONArray.toArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONArray.toArray()
方法的具体详情如下:
包路径:net.sf.json.JSONArray
类名称:JSONArray
方法名:toArray
暂无
代码示例来源:origin: jenkinsci/jenkins
@DataBoundConstructor
public Plugin(String sourceId, JSONObject o) {
super(sourceId, o, UpdateSite.this.url);
this.wiki = get(o,"wiki");
this.title = get(o,"title");
this.excerpt = get(o,"excerpt");
this.compatibleSinceVersion = Util.intern(get(o,"compatibleSinceVersion"));
this.minimumJavaVersion = Util.intern(get(o, "minimumJavaVersion"));
this.requiredCore = Util.intern(get(o,"requiredCore"));
this.categories = o.has("labels") ? internInPlace((String[])o.getJSONArray("labels").toArray(EMPTY_STRING_ARRAY)) : null;
JSONArray ja = o.getJSONArray("dependencies");
int depCount = (int)(ja.stream().filter(IS_DEP_PREDICATE.and(IS_NOT_OPTIONAL)).count());
int optionalDepCount = (int)(ja.stream().filter(IS_DEP_PREDICATE.and(IS_NOT_OPTIONAL.negate())).count());
dependencies = getPresizedMutableMap(depCount);
optionalDependencies = getPresizedMutableMap(optionalDepCount);
for(Object jo : o.getJSONArray("dependencies")) {
JSONObject depObj = (JSONObject) jo;
// Make sure there's a name attribute and that the optional value isn't true.
String depName = Util.intern(get(depObj,"name"));
if (depName!=null) {
if (get(depObj, "optional").equals("false")) {
dependencies.put(depName, Util.intern(get(depObj, "version")));
} else {
optionalDependencies.put(depName, Util.intern(get(depObj, "version")));
}
}
}
}
代码示例来源:origin: stackoverflow.com
try { ...
JSONObject rootJSON = (JSONObject) new JSONParser().parse(jsonString);
JSONArray dataList = (JSONArray) rootJSON.get("data");
for(Object projectObj: dataList.toArray()){
JSONObject project = (JSONObject)projectObj;
JSONArray issueList = (JSONArray) project.get("issue");
for(Object issueObj: issueList.toArray()){
JSONObject issue = (JSONObject) issueObj;
//do something with the issue
}
}
} catch (ParseException e) {
//do smth
e.printStackTrace();
}
代码示例来源:origin: zhangdaiscott/jeewx-api
public static Object json2Array(String json, Class valueClz) {
JSONArray jsonArray = JSONArray.fromObject(json);
return JSONArray.toArray(jsonArray, valueClz);
}
代码示例来源:origin: gooddata/GoodData-CL
/**
* Returns formatted error message if the message contains parameters
* placeholder (%s)
*
* @param error
* @return
*/
private static String formatErrorMessage(JSONObject error) {
final String orig = error.getString("message");
if (!orig.contains("%s")) {
return orig;
}
return new Formatter().format(orig, error.getJSONArray("parameters").toArray()).toString();
}
代码示例来源:origin: stackoverflow.com
try {
URL url = new URL("http://localhost/api.php");
URLConnection conn = url.openConnection();
conn.setDoInput(true);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
String content = "command=getCompanies";
out.writeBytes(content);
out.flush();
out.close();
InputStream is = conn.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String wholeLine = "";
String line;
while ((line = rd.readLine()) != null) {
wholeLine = wholeLine + line;
}
is.close();
JSONArray array = (JSONArray) new JSONParser().parse(wholeLine);
for(Object obj : array.toArray()){
System.out.println(obj.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
代码示例来源:origin: org.zaproxy/zap
@Override
public void init(String config) {
try {
JSONObject json = JSONObject.fromObject(config);
this.setKeyValuePairSeparators(json.getString(CONFIG_KV_PAIR_SEPARATORS));
this.setKeyValueSeparators(json.getString(CONFIG_KV_SEPARATORS));
JSONArray ja = json.getJSONArray(CONFIG_STRUCTURAL_PARAMS);
for (Object obj : ja.toArray()) {
this.structuralParameters.add(obj.toString());
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
代码示例来源:origin: itesla/ipst
public Collection<Collection<String>> getTopologyDescription(String id, String topoHash) {
try (InputStream is = httpClient.getHttpRequest(new HistoDbUrl(config, "itesla/topos/" + id + "/" + topoHash + ".json", Collections.emptyMap()))) {
byte[] bytes = ByteStreams.toByteArray(is);
Collection<Collection<String>> result = new HashSet<>();
JSONArray topology = JSONArray.fromObject(new String(bytes, Charset.forName("UTF-8")));
for (int i = 0; i < topology.size(); i++) {
JSONArray jsonConnectedSet = topology.getJSONArray(i);
Collection<String> connectedSet = Arrays.asList((String[]) jsonConnectedSet.toArray(new String[]{}));
result.add(connectedSet);
}
return result;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
代码示例来源:origin: itesla/ipst
@Override
public List<SecurityRule> getRules(String workflowId, RuleAttributeSet attributeSet, String contingencyId, SecurityIndexType securityIndexType) {
Objects.requireNonNull(workflowId);
Objects.requireNonNull(attributeSet);
StringBuilder path = new StringBuilder();
path.append(RULES_PREFIX).append(workflowId)
.append("/itesla/rules/").append(attributeSet);
if (contingencyId != null) {
path.append("/").append(contingencyId);
}
if (securityIndexType != null) {
path.append("/").append(securityIndexType.getLabel());
}
path.append(".json");
List<SecurityRule> result = new ArrayList<>();
try (InputStream is = httpClient.getHttpRequest(new HistoDbUrl(config, path.toString(), Collections.emptyMap()))) {
String stringResult = new String(ByteStreams.toByteArray(is), StandardCharsets.UTF_8);
for (Object jsonRule: JSONArray.fromObject(stringResult).toArray()) {
result.add(JsonSecurityRule.fromJSON((JSONObject) jsonRule));
}
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
throw new RuntimeException("Failed to encode rule", e);
}
return result;
}
代码示例来源:origin: org.apache.struts/struts2-rest-plugin
public void toObject(ActionInvocation invocation, Reader in, Object target) throws IOException {
StringBuilder sb = new StringBuilder();
char[] buffer = new char[1024];
int len = 0;
while ((len = in.read(buffer)) > 0) {
sb.append(buffer, 0, len);
}
if (target != null && sb.length() > 0 && sb.charAt(0) == '[') {
JSONArray jsonArray = JSONArray.fromObject(sb.toString());
if (target.getClass().isArray()) {
JSONArray.toArray(jsonArray, target, new JsonConfig());
} else {
JSONArray.toList(jsonArray, target, new JsonConfig());
}
} else {
JSONObject jsonObject = JSONObject.fromObject(sb.toString());
JSONObject.toBean(jsonObject, target, new JsonConfig());
}
}
代码示例来源:origin: edu.uiuc.ncsa.myproxy/oa4mp-server-loader-oauth2
public static AttributeRemoveRequest createRequest(AdminClient aSubj,
TypeAttribute typeAttribute,
ActionRemove actionRemove,
OA2Client cTarget,
JSON content) {
//JSON content = SATFactory.getContent(json);
if (!content.isArray()) {
throw new GeneralException("Content must be a list of attributes to get");
}
JSONArray array = (JSONArray) content;
String[] arrayString = (String[]) array.toArray(new String[array.size()]);
return new AttributeRemoveRequest(aSubj, cTarget, Arrays.asList(arrayString));
}
代码示例来源:origin: edu.uiuc.ncsa.myproxy/oa4mp-server-loader-oauth2
public static AttributeGetRequest createRequest(AdminClient aSubj,
TypeAttribute typeAttribute,
ActionGet actionGet,
OA2Client cTarget,
JSON content) {
//JSON content = SATFactory.getContent(json);
if (!content.isArray()) {
throw new GeneralException("Content must be a list of attributes to get");
}
JSONArray array = (JSONArray) content;
String[] arrayString = (String[]) array.toArray(new String[array.size()]);
return new AttributeGetRequest(aSubj, cTarget, Arrays.asList(arrayString));
}
代码示例来源:origin: gooddata/GoodData-CL
/**
* Constructs a new SLI column
*
* @param column the JSON object from the GoodData REST API
*/
public Column(JSONObject column) {
name = column.getString("columnName");
mode = column.getString("mode");
JSONArray pa = column.getJSONArray("populates");
populates = new String[pa.size()];
for (int i = 0; i < pa.size(); i++) {
populates[i] = pa.getString(i);
}
populates = (String[]) pa.toArray(populates);
if (column.containsKey("referenceKey"))
referenceKey = column.getInt("referenceKey");
}
代码示例来源:origin: org.eclipse.hudson/hudson-core
String[] labels = (String[]) jsonObject.getJSONArray("labels").toArray(new String[0]);
for (String label : labels) {
String category = getCategoryDisplayName(label);
代码示例来源:origin: gooddata/GoodData-CL
if (!failed.isEmpty()) {
String errMsg = "Following users can't be added to the project:";
for (Object uri : failed.toArray()) {
errMsg += " " + uris.toString();
代码示例来源:origin: hudson/hudson-2.x
@DataBoundConstructor
public Plugin(String sourceId, JSONObject o) {
super(sourceId, o);
this.wiki = get(o,"wiki");
this.title = get(o,"title");
this.excerpt = get(o,"excerpt");
this.compatibleSinceVersion = get(o,"compatibleSinceVersion");
this.requiredCore = get(o,"requiredCore");
this.categories = o.has("labels") ? (String[])o.getJSONArray("labels").toArray(new String[0]) : null;
for(Object jo : o.getJSONArray("dependencies")) {
JSONObject depObj = (JSONObject) jo;
// Make sure there's a name attribute, that that name isn't maven-plugin - we ignore that one -
// and that the optional value isn't true.
if (get(depObj,"name")!=null
&& !get(depObj,"name").equals("maven-plugin")
&& get(depObj,"optional").equals("false")) {
dependencies.put(get(depObj,"name"), get(depObj,"version"));
}
}
}
代码示例来源:origin: org.jvnet.hudson.main/hudson-core
@DataBoundConstructor
public Plugin(String sourceId, JSONObject o) {
super(sourceId, o);
this.wiki = get(o,"wiki");
this.title = get(o,"title");
this.excerpt = get(o,"excerpt");
this.compatibleSinceVersion = get(o,"compatibleSinceVersion");
this.requiredCore = get(o,"requiredCore");
this.categories = o.has("labels") ? (String[])o.getJSONArray("labels").toArray(new String[0]) : null;
for(Object jo : o.getJSONArray("dependencies")) {
JSONObject depObj = (JSONObject) jo;
// Make sure there's a name attribute, that that name isn't maven-plugin - we ignore that one -
// and that the optional value isn't true.
if (get(depObj,"name")!=null
&& !get(depObj,"name").equals("maven-plugin")
&& get(depObj,"optional").equals("false")) {
dependencies.put(get(depObj,"name"), get(depObj,"version"));
}
}
}
代码示例来源:origin: org.eclipse.hudson.main/hudson-core
@DataBoundConstructor
public Plugin(String sourceId, JSONObject o) {
super(sourceId, o);
this.wiki = get(o,"wiki");
this.title = get(o,"title");
this.excerpt = get(o,"excerpt");
this.compatibleSinceVersion = get(o,"compatibleSinceVersion");
this.requiredCore = get(o,"requiredCore");
this.categories = o.has("labels") ? (String[])o.getJSONArray("labels").toArray(new String[0]) : null;
for(Object jo : o.getJSONArray("dependencies")) {
JSONObject depObj = (JSONObject) jo;
// Make sure there's a name attribute, that that name isn't maven-plugin - we ignore that one -
// and that the optional value isn't true.
if (get(depObj,"name")!=null
&& !get(depObj,"name").equals("maven-plugin")
&& get(depObj,"optional").equals("false")) {
dependencies.put(get(depObj,"name"), get(depObj,"version"));
}
}
}
代码示例来源:origin: org.jenkins-ci.main/jenkins-core
@DataBoundConstructor
public Plugin(String sourceId, JSONObject o) {
super(sourceId, o, UpdateSite.this.url);
this.wiki = get(o,"wiki");
this.title = get(o,"title");
this.excerpt = get(o,"excerpt");
this.compatibleSinceVersion = get(o,"compatibleSinceVersion");
this.requiredCore = get(o,"requiredCore");
this.categories = o.has("labels") ? (String[])o.getJSONArray("labels").toArray(new String[0]) : null;
for(Object jo : o.getJSONArray("dependencies")) {
JSONObject depObj = (JSONObject) jo;
// Make sure there's a name attribute and that the optional value isn't true.
if (get(depObj,"name")!=null) {
if (get(depObj, "optional").equals("false")) {
dependencies.put(get(depObj, "name"), get(depObj, "version"));
} else {
optionalDependencies.put(get(depObj, "name"), get(depObj, "version"));
}
}
}
}
代码示例来源:origin: org.eclipse.hudson/hudson-core
@DataBoundConstructor
public Plugin(String sourceId, JSONObject o) {
super(sourceId, o);
this.type = get(o, "type");
if ((type == null) || "".equals(type)) {
type = "others";
}
this.wiki = get(o, "wiki");
this.title = get(o, "title");
this.excerpt = get(o, "excerpt");
this.compatibleSinceVersion = get(o, "compatibleSinceVersion");
this.requiredCore = get(o, "requiredCore");
JSONArray labelsJsonArray = o.getJSONArray("labels");
this.categories = o.has("labels") ? (String[]) labelsJsonArray.toArray(new String[labelsJsonArray.size()]) : null;
for (Object jo : o.getJSONArray("dependencies")) {
JSONObject depObj = (JSONObject) jo;
// Make sure there's a name attribute, that that name isn't maven-plugin - we ignore that one -
// and that the optional value isn't true.
if (get(depObj, "name") != null
&& !get(depObj, "name").equals("maven-plugin")
&& get(depObj, "optional").equals("false")) {
dependencies.put(get(depObj, "name"), get(depObj, "version"));
}
}
}
代码示例来源:origin: org.jenkins-ci.plugins/scriptler
/**
* Extracts the parameters from the given request
*
* @param req
* the request potentially containing parameters
* @return parameters - might be an empty array, but never <code>null</code>.
* @throws ServletException
*/
public static Parameter[] extractParameters(JSONObject json) throws ServletException {
Parameter[] parameters = new Parameter[0];
final JSONObject defineParams = json.optJSONObject("defineParams");
if (defineParams != null && !defineParams.isNullObject()) {
JSONObject argsObj = defineParams.optJSONObject("parameters");
if (argsObj == null) {
JSONArray argsArrayObj = defineParams.optJSONArray("parameters");
if (argsArrayObj != null) {
parameters = (Parameter[]) JSONArray.toArray(argsArrayObj, Parameter.class);
}
} else {
Parameter param = (Parameter) JSONObject.toBean(argsObj, Parameter.class);
parameters = new Parameter[] { param };
}
}
return parameters;
}
}
内容来源于网络,如有侵权,请联系作者删除!