本文整理汇总了Java中org.json.simple.JSONObject.keySet方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.keySet方法的具体用法?Java JSONObject.keySet怎么用?Java JSONObject.keySet使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.simple.JSONObject
的用法示例。
在下文中一共展示了JSONObject.keySet方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDetail
import org.json.simple.JSONObject; //导入方法依赖的package包/类
public DockerImageDetail getDetail(DockerImage image) throws DockerException {
JSONObject value = (JSONObject) doGetRequest("/images/" + image.getId() + "/json",
Collections.singleton(HttpURLConnection.HTTP_OK));
List<ExposedPort> ports = new LinkedList<>();
JSONObject config = (JSONObject) value.get("Config");
if (config != null) {
JSONObject portsObject = (JSONObject) config.get("ExposedPorts");
if (portsObject != null) {
for (Object k : portsObject.keySet()) {
String portStr = (String) k;
Matcher m = PORT_PATTERN.matcher(portStr);
if (m.matches()) {
int port = Integer.parseInt(m.group(1));
ExposedPort.Type type = ExposedPort.Type.valueOf(m.group(2).toUpperCase(Locale.ENGLISH));
ports.add(new ExposedPort(port, type));
} else {
LOGGER.log(Level.FINE, "Unparsable port: {0}", portStr);
}
}
}
}
return new DockerImageDetail(ports);
}
示例2: parseJSON
import org.json.simple.JSONObject; //导入方法依赖的package包/类
private static Map<String, String> parseJSON(String json) {
Map<String, String> map = new HashMap<String, String>();
if (json != null && json.length() > 2) {
try {
JSONParser parser = new JSONParser();
JSONObject obj = (JSONObject) parser.parse(json);
for (Object entry: obj.keySet()) {
String key = entry.toString();
String value = obj.get(entry).toString();
map.put(key, value);
}
} catch (ParseException e) {
e.printStackTrace();
}
}
return map;
}
示例3: toMap
import org.json.simple.JSONObject; //导入方法依赖的package包/类
public static Map<String, Object> toMap(JSONObject jsonObject) throws JSONException {
Map<String, Object> map = new HashMap<>();
for (Object key : jsonObject.keySet()) {
Object value = jsonObject.get(key);
if (value instanceof JSONObject) {
value = MapUtil.toMap((JSONObject) value);
}
if (value instanceof JSONArray) {
value = ArrayUtil.toArray((JSONArray) value);
}
map.put(String.valueOf(key), value);
}
return map;
}
示例4: getPageMap
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
* parse and map the pages and its page timings
*
* @param data json data
* @return json map
*/
private static JSONObject getPageMap(String data) {
JSONObject pageMap = new JSONObject();
JSONObject ob = (JSONObject) JSONValue.parse(data);
for (Object tc : ob.keySet()) {
JSONArray hars = (JSONArray) ((JSONObject) ob.get(tc)).get("har");
for (Object e : hars) {
JSONObject har = (JSONObject) ((JSONObject) e).get("har");
JSONObject page = (JSONObject) ((JSONArray) (((JSONObject) har.get("log")).get("pages"))).get(0);
Object pagename = ((JSONObject) har.get("config")).get("name");
if (!pageMap.containsKey(pagename)) {
pageMap.put(pagename, new JSONArray());
}
JSONObject pageData = (JSONObject) page.get("pageTimings");
pageData.put("config", har.get("config"));
((JSONArray) pageMap.get(pagename)).add(pageData);
}
}
return pageMap;
}
示例5: MergeServer
import org.json.simple.JSONObject; //导入方法依赖的package包/类
public MergeServer(ResultSet rs) throws SQLException
{
serverid = (UUID)rs.getObject("serverid");
hostname = rs.getString("hostname");
address = rs.getString("address");
lastcheck = rs.getTimestamp("lastcheck", Database.utc);
nextcheck = rs.getTimestamp("nextcheck", Database.utc);
waittime = rs.getInt("waittime");
ctimeout = rs.getInt("ctimeout");
cfailures = rs.getInt("cfailures");
String hs = rs.getString("hoststate");
switch (hs) {
case "A": hoststate = HostState.ACTIVE; break;
case "1": hoststate = HostState.ONESHOT; break;
case "I": hoststate = HostState.INACTIVE; break;
default: hoststate = HostState.UNKNOWN; break;
}
seriesstate = new HashMap<String, JSONObject>();
try {
JSONObject mergestate = (JSONObject)new JSONParser().parse(rs.getString("mergestate"));
for (Object o : mergestate.keySet()) {
seriesstate.put((String)o, (JSONObject)mergestate.get(o));
}
} catch (ParseException e) {
}
}
示例6: toMap
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
* Convert json object to map.
* @param object source json
* @return map
*/
@SuppressWarnings("unchecked")
private Map<String, Object> toMap(JSONObject object) {
Map<String, Object> map = new HashMap<String, Object>();
Set<String> keys = object.keySet();
for (String key : keys) {
Object value = object.get(key);
if (value instanceof JSONArray) {
value = toList((JSONArray) value);
} else if (value instanceof JSONObject) {
value = toMap((JSONObject) value);
}
map.put(key, value);
}
return map;
}
示例7: TestSuite
import org.json.simple.JSONObject; //导入方法依赖的package包/类
public TestSuite(JSONObject testCaseJSONObj) throws ParseException {
for (Object key : testCaseJSONObj.keySet()) {
Object testCaseJSON = testCaseJSONObj.get(key);
TestCase testCase = new TestCase(key.toString(), (JSONObject) testCaseJSON);
testList.add(testCase);
}
}
示例8: testPremineFromJSON
import org.json.simple.JSONObject; //导入方法依赖的package包/类
@Test
public void testPremineFromJSON() throws ParseException {
JSONParser parser = new JSONParser();
JSONObject genesisMap = (JSONObject) parser.parse(TEST_GENESIS);
Set keys = genesisMap.keySet();
Trie state = new TrieImpl(null, true);
for (Object key : keys) {
JSONObject val = (JSONObject) genesisMap.get(key);
String denom = (String) val.keySet().toArray()[0];
String value = (String) val.values().toArray()[0];
BigInteger wei = Denomination.valueOf(denom.toUpperCase()).value().multiply(new BigInteger(value));
AccountState accountState = new AccountState(BigInteger.ZERO, wei);
byte[] encodedAccountState = accountState.getEncoded();
byte[] accountKey = Hex.decode(key.toString());
state = state.put(accountKey, encodedAccountState);
Assert.assertArrayEquals(encodedAccountState, state.get(accountKey));
}
logger.info("root: " + Hex.toHexString(state.getHash()));
assertEquals(GENESIS_STATE_ROOT, Hex.toHexString(state.getHash()));
}
示例9: toDataPoint
import org.json.simple.JSONObject; //导入方法依赖的package包/类
private static DataPoint toDataPoint(JSONObject jsonObject) {
assertEquals(4, jsonObject.size());
String metricName = (String) jsonObject.get("metric");
long epoch = (Long) jsonObject.get("timestamp");
long value = (Long) jsonObject.get("value");
Map<String, String> tags = new HashMap<>();
JSONObject tagsObject = (JSONObject) jsonObject.get("tags");
Set keys = tagsObject.keySet();
for (Object key : keys) {
tags.put((String) key, (String) tagsObject.get(key));
}
return new DataPoint(metricName, epoch, value, tags);
}
示例10: getFields
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
* returns the list of modules
*
* @param moduleId
* @return
*/
public List<HashMap<String, String>> getFields(String moduleId) {
List<HashMap<String, String>> fields = new ArrayList<>();
JSONObject moduleData = (JSONObject) ((JSONObject) data.get("fields")).get(moduleId);
for (Object key : moduleData.keySet()) {
HashMap<String, String> properties = (HashMap<String, String>) moduleData.get(key);
fields.add(properties);
}
return fields;
}
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:16,代码来源:ReportingModuleSettings.java
示例11: getVersionID
import org.json.simple.JSONObject; //导入方法依赖的package包/类
public static int getVersionID(String versionName, int projID,
JIRAHttpClient client) {
int vid = -1;
try {
URL projListUrl = new URL(client.url.toString() + VERSIONLIST
+ String.valueOf(projID));
DLogger.Log("Req Version List with Project ID [", projID, "] ",
projListUrl.toString());
JSONObject versionInfo = client.Get(projListUrl);
DLogger.Log("Looking for [", versionName, "] in", versionInfo);
for (Object versionType : versionInfo.keySet()) {
for (Object version : (Iterable<? extends Object>) versionInfo
.get(versionType)) {
// for diff. type of VERSIONS groups., array.VERSIONS changed
// to iterate all types
if (((Map<?, ?>) version).get("label").toString()
.equalsIgnoreCase(versionName)) {
vid = Integer.valueOf(((Map<?, ?>) version)
.get("value").toString());
break;
}
}
}
if (vid == -1) {
DLogger.LogE("Release/Version [", versionName, "] not found");
}
} catch (Exception ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
return vid;
}
示例12: getCycleId
import org.json.simple.JSONObject; //导入方法依赖的package包/类
static int getCycleId(String cycleName, int versionID, JIRAHttpClient client) {
int cid = -1;
try {
URL reqUrl = new URL(client.url.toString() + CYCLELIST
+ String.valueOf(versionID));
DLogger.Log("Req Cycle List with Version ID [", versionID, "] ",
reqUrl.toString());
JSONObject cycleList = client.Get(reqUrl);
DLogger.Log("Looking for [", cycleName, "] in", cycleList);
for (Object key : cycleList.keySet()) {
if (cycleList.get(key) instanceof Map) {
Map<?, ?> cycle = (Map<?, ?>) cycleList.get(key);
if (cycle.get("name").toString()
.equalsIgnoreCase(cycleName)) {
cid = Integer.valueOf(key.toString());
break;
}
}
}
} catch (Exception ex) {
LOG.log(Level.SEVERE, ex.getMessage(), ex);
}
if (cid == -1) {
DLogger.LogE("TestSet/Cycle [", cycleName, "] not found");
}
return cid;
}
示例13: transferFromJSON
import org.json.simple.JSONObject; //导入方法依赖的package包/类
/**
* Transfers data from the old config type: JSON.
*
* @throws Exception If file config.json cannot be found.
*/
private static void transferFromJSON() throws Exception {
File file = new File(ZLevels.getDirectory(), "config.json");
FileReader reader = new FileReader(file);
JSONObject data = (JSONObject) new JSONParser().parse(reader);
Yaml yaml = Yaml.loadConfiguration(new InputStreamReader(ZLevels.class.getResourceAsStream("/config.yml")));
for (Object key : data.keySet()) {
Object value = data.get(key.toString());
switch (key.toString()) {
case "NAME":
case "TOKEN":
case "PREFIX":
case "SERVER":
case "DB_HOST":
case "DB_PORT":
case "DB_NAME":
case "DB_USER":
case "DB_PASS":
case "STAFF_ROLE":
yaml.set(getNewKey(key.toString()), value.toString());
break;
case "OPS":
case "CHANNELS_FOR_RATINGS":
yaml.set(getNewKey(key.toString()), ((JSONArray) value).toArray(new String[0]));
break;
case "AUTOROLE_ENABLED":
case "RATINGS_ENABLED":
yaml.set(getNewKey(key.toString()), Boolean.parseBoolean(value.toString()));
break;
case "ERROR_MILLIS":
yaml.set(getNewKey(key.toString()), Long.parseLong(value.toString()));
}
}
yaml.save(new File(file.getParentFile(), "config.yml"));
ZLogger.info("Successfully loaded data from old config.");
}
示例14: testPremineFromJSON
import org.json.simple.JSONObject; //导入方法依赖的package包/类
@Test
public void testPremineFromJSON() throws ParseException {
JSONParser parser = new JSONParser();
JSONObject genesisMap = (JSONObject) parser.parse(TEST_GENESIS);
Set keys = genesisMap.keySet();
Trie state = new SecureTrie((byte[]) null);
for (Object key : keys) {
JSONObject val = (JSONObject) genesisMap.get(key);
String denom = (String) val.keySet().toArray()[0];
String value = (String) val.values().toArray()[0];
BigInteger wei = Denomination.valueOf(denom.toUpperCase()).value().multiply(new BigInteger(value));
AccountState acctState = new AccountState(BigInteger.ZERO, wei);
state.put(Hex.decode(key.toString()), acctState.getEncoded());
}
logger.info("root: " + Hex.toHexString(state.getRootHash()));
assertEquals(GENESIS_STATE_ROOT, Hex.toHexString(state.getRootHash()));
}
示例15: getRequestSignProperties
import org.json.simple.JSONObject; //导入方法依赖的package包/类
private Map<String, String> getRequestSignProperties (String method, URL url, JSONObject params, JSONObject payload) {
Map<String, String> requestSignProperties = new HashMap<String, String>();
String timestamp = Instant.now().toString().substring(0, 19) + "Z";
List<String> req = new ArrayList<String>();
req.add(method);
req.add(url.getAuthority());
req.add("443");
req.add(url.getPath());
if (this.accessToken != null) {
req.add(this.accessToken);
} else {
req.add("");
}
req.add(timestamp);
if (params != null) {
List<String> paramsList = new ArrayList<String>();
for (Object key : params.keySet()) {
String paramString = "";
//based on you key types
String keyStr = (String)key;
Object keyVal = params.get(keyStr);
paramString += keyStr + "%" + keyVal;
paramsList.add(paramString);
}
req.add(String.join("%", paramsList));
} else {
req.add("");
}
if (payload != null) {
String payloadString = payload.toString().replace(":", ": ").replace(",", ", ");
req.add(payloadString);
} else {
req.add("");
}
String hmacData = String.join("%", req);
String signature = null;
try {
signature = JodelHelper.calculateHMAC(JodelAccount.SECRET, hmacData);
} catch (Exception e) {
e.printStackTrace();
return null;
}
requestSignProperties.put("X-Authorization", "HMAC " + signature);
requestSignProperties.put("X-Client-Type","android_" + JodelAccount.VERSION);
requestSignProperties.put("X-Timestamp", timestamp);
requestSignProperties.put("X-Api-Version", "0.2");
return requestSignProperties;
}