本文整理匯總了Java中org.json.JSONObject.getNames方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.getNames方法的具體用法?Java JSONObject.getNames怎麽用?Java JSONObject.getNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.getNames方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getContainerName
import org.json.JSONObject; //導入方法依賴的package包/類
@Override public String getContainerName(JSONObject container) throws JSONException, ObjectMapException {
// For a container we shall use urp to generate the name
JSONObject attributes = container.getJSONObject("attributes");
String name;
if (attributes.has("suggestedName")) {
name = attributes.getString("suggestedName");
} else {
JSONObject urp = container.getJSONObject("urp");
StringBuilder sb = new StringBuilder();
String[] keys = JSONObject.getNames(urp);
for (String key : keys) {
sb.append(urp.get(key).toString()).append(':');
}
sb.setLength(sb.length() - 1);
name = sb.toString();
}
return getName(container, name);
}
示例2: fromJSONObject
import org.json.JSONObject; //導入方法依賴的package包/類
public void fromJSONObject(JSONObject jsonTuple)
{
this.reset();
try {
String[] fieldnames = JSONObject.getNames(jsonTuple);
for(int index=0; index<fieldnames.length; index++)
{
String fieldname = fieldnames[index];
Object fieldvalue = jsonTuple.get(fieldname);
this.addField(fieldname, fieldvalue);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: normalizeObject
import org.json.JSONObject; //導入方法依賴的package包/類
protected JSONObject normalizeObject(JSONObject obj) {
LOGGER.debug("NORM: " + obj.toString());
for (String key : JSONObject.getNames(obj)) {
JSONObject subtree = obj.optJSONObject(key);
if (subtree != null) {
if (subtree.has(ARRAY)) {
// Set the array as the direct value
JSONArray subarray = subtree.getJSONArray(ARRAY);
obj.put(key, subarray);
LOGGER.debug("recurse with {}: {}", key, subtree.toString());
}
// See if there's more to do in this subtree
normalizeObject(subtree);
}
}
return obj;
}
示例4: asProperties
import org.json.JSONObject; //導入方法依賴的package包/類
public static Properties asProperties(JSONObject jsonObject) {
Properties r = new Properties();
String[] names = JSONObject.getNames(jsonObject);
if (names != null) {
for (String name : names) {
r.setProperty(name, jsonObject.get(name).toString());
}
}
return r;
}
示例5: compareProperties
import org.json.JSONObject; //導入方法依賴的package包/類
private void compareProperties(JSONObject before, JSONObject after) throws JSONException
{
for (String name : JSONObject.getNames(after))
{
if (before.has(name))
{
if (before.get(name) instanceof JSONArray)
{
for (int i = 0; i < before.getJSONArray(name).length(); i++)
{
assertEquals(before.getJSONArray(name).get(i), after.getJSONArray(name).get(i));
}
}
else
{
assertEquals(before.get(name), after.get(name));
}
}
}
}
示例6: toMap
import org.json.JSONObject; //導入方法依賴的package包/類
public static Map<String, Object> toMap(JSONObject object) {
Map<String, Object> map = new HashMap<>();
String[] fields = JSONObject.getNames(object);
for (String field : fields) {
Object entry = object.get(field);
if (entry instanceof JSONObject) {
map.put(field, toMap((JSONObject) entry));
} else if (entry instanceof JSONArray) {
map.put(field, toCollection((JSONArray) entry));
} else {
map.put(field, entry);
}
}
return map;
}
示例7: parseJSONSettings
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Takes jsonSettings parameter and inserts all Key-Value pairs into the settings map
* <p>
* Recursively passes child json objects into itself with there path as the new base path. Utilizing {@link
* ApplicationSettings#bindPath(String, String)} to link the new paths to the base path.
* <p>
* NOTE: Expects a json object with keys mapping to JSON objects or Strings ONLY. It will fail fast otherwise.
*
* @param jsonSettings
* JSON Object of settings file
* @param basePath
* Starting path to prefix onto new keys
*/
private static void parseJSONSettings( JSONObject jsonSettings, String basePath )
{
for ( String key : JSONObject.getNames(jsonSettings) )
{
Object value = jsonSettings.get(key);
if ( value instanceof String )
{
settings.put(bindPath(basePath, key), (String) value);
} else
{
parseJSONSettings(jsonSettings.getJSONObject(key), bindPath(basePath, key));
}
}
}
示例8: resetInstance
import org.json.JSONObject; //導入方法依賴的package包/類
public void resetInstance(AbstractPreferences oldInstance) {
listeners = oldInstance.listeners;
String[] names = JSONObject.getNames(prefs);
if (names != null) {
for (String section : names) {
firePreferenceChange(section);
}
}
}
示例9: toCSS
import org.json.JSONObject; //導入方法依賴的package包/類
public static String toCSS(JSONObject urp) {
Properties props = new Properties();
String[] names = JSONObject.getNames(urp);
for (String prop : names) {
props.setProperty(prop, urp.get(prop).toString());
}
return toCSS(props);
}
示例10: fromJSONObject
import org.json.JSONObject; //導入方法依賴的package包/類
public void fromJSONObject(JSONObject jsonBatch) {
this.reset();
try {
// get id
long batchid = jsonBatch.getLong("ID");
this.m_id = batchid;
// get timestamp
this.m_timestamp = jsonBatch.getLong("TIMESTAMP");
this.m_endtimestamp = jsonBatch.getLong("ENDTIMESTAMP");
JSONArray jsonBatchTuples = jsonBatch.getJSONArray("TUPLES");
JSONObject jsonTuple;
for (int i = 0; i < jsonBatchTuples.length(); i++) {
jsonTuple = jsonBatchTuples.getJSONObject(i);
Tuple tuple = new Tuple();
String[] fieldnames = JSONObject.getNames(jsonTuple);
for (int index = 0; index < fieldnames.length; index++) {
String fieldname = fieldnames[index];
Object fieldvalue = jsonTuple.get(fieldname);
tuple.addField(fieldname, fieldvalue);
}
this.addTuple(tuple);
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例11: search
import org.json.JSONObject; //導入方法依賴的package包/類
public boolean search(String find) {
for (String jsonName : JSONObject.getNames(json)) {
Object value = json.get(jsonName);
if (searchMatch(find, value))
return true;
}
return false;
}
示例12: ServiceSummary
import org.json.JSONObject; //導入方法依賴的package包/類
public ServiceSummary(JSONObject json) throws JSONException {
if (json.has("publicUserId"))
this.publicUserId = json.getString("publicUserId");
if (json.has("requestId"))
this.requestId = json.getString("requestId");
if (json.has("microservices")) {
JSONObject summaryJson = json.getJSONObject("microservices");
for (String microservice : JSONObject.getNames(summaryJson)) {
Microservice microInvokes = new Microservice(microservice, summaryJson.getJSONObject(microservice));
microserviceSummaries.add(microInvokes);
}
}
}
示例13: run
import org.json.JSONObject; //導入方法依賴的package包/類
public Result run(String[] args, MessageReceivedEvent e) {
//Request information from Mojang
String request = RequestUtils.get("https://status.mojang.com/check");
if (request == null) {
return new Result(Outcome.ERROR, ":x: The Mojang API could not be reached.");
}
Color color = Color.GREEN;
//Iterate over response sections
ArrayList<String> responses = new ArrayList<String>();
JSONArray status = new JSONArray(request);
for (int i = 0; i < status.length(); i++) {
//Fetch the response
JSONObject json = status.getJSONObject(i);
String[] names = JSONObject.getNames(json);
String response = json.getString(names[0]);
//Parse the response
String output = ":x:";
if (response.equals("green")) {
output = ":white_check_mark:";
} else if (response.equals("yellow")) {
output = ":warning:";
if (color != Color.RED) {
color = Color.YELLOW;
}
} else {
color = Color.RED;
}
responses.add(output);
}
//Build message
String m = "**Minecraft:** " + responses.get(0) +
"\n" + "**Skins:** " + responses.get(4) +
"\n" + "**Textures:** " + responses.get(8) +
"\n" + "**Session:** " + responses.get(1) +
"\n" + "**Session Server:** " + responses.get(6) +
"\n" + "**Accounts:** " + responses.get(2) +
"\n" + "**Auth:** " + responses.get(3) +
"\n" + "**Auth Server:** " + responses.get(5) +
"\n" + "**Mojang:** " + responses.get(9) +
"\n" + "**Mojang API:** " + responses.get(7);
MessageEmbed me = MessageUtils.embedMessage("Minecraft Status", null, m, color);
return new Result(Outcome.SUCCESS, me);
}
示例14: incPageCommentCount
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Page comment count +1 for an page specified by the given page id.
*
* @param pageId
* the given page id
* @throws JSONException
* json exception
* @throws RepositoryException
* repository exception
*/
public void incPageCommentCount(final String pageId) throws JSONException, RepositoryException {
final JSONObject page = pageDao.get(pageId);
final JSONObject newPage = new JSONObject(page, JSONObject.getNames(page));
final int commentCnt = page.getInt(Page.PAGE_COMMENT_COUNT);
newPage.put(Page.PAGE_COMMENT_COUNT, commentCnt + 1);
pageDao.update(pageId, newPage);
}
示例15: decPageCommentCount
import org.json.JSONObject; //導入方法依賴的package包/類
/**
* Page comment count -1 for an page specified by the given page id.
*
* @param pageId
* the given page id
* @throws JSONException
* json exception
* @throws RepositoryException
* repository exception
*/
private void decPageCommentCount(final String pageId) throws JSONException, RepositoryException {
final JSONObject page = pageDao.get(pageId);
final JSONObject newPage = new JSONObject(page, JSONObject.getNames(page));
final int commentCnt = page.getInt(Page.PAGE_COMMENT_COUNT);
newPage.put(Page.PAGE_COMMENT_COUNT, commentCnt - 1);
pageDao.update(pageId, newPage);
}