本文整理匯總了Java中org.json.simple.JSONObject.containsKey方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONObject.containsKey方法的具體用法?Java JSONObject.containsKey怎麽用?Java JSONObject.containsKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.json.simple.JSONObject
的用法示例。
在下文中一共展示了JSONObject.containsKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: Style
import org.json.simple.JSONObject; //導入方法依賴的package包/類
Style(JSONObject style, String preferredId) {
if (preferredId != null) {
id = new StyleId(preferredId);
} else {
if (style.containsKey("styleId")) { // NOI18N
id = new StyleId((JSONObject)style.get("styleId")); // NOI18N
} else if (style.containsKey("styleSheetId")) { // NOI18N
id = new StyleId((String)style.get("styleSheetId")); // NOI18N
} else {
id = null;
}
}
JSONArray cssProperties = (JSONArray)style.get("cssProperties"); // NOI18N
properties = new ArrayList<Property>(cssProperties.size());
for (Object o : cssProperties) {
JSONObject cssProperty = (JSONObject)o;
Property property = new Property(cssProperty);
properties.add(property);
}
text = (String)style.get("cssText"); // NOI18N
if (style.containsKey("range")) { // NOI18N
range = new SourceRange((JSONObject)style.get("range")); // NOI18N
}
}
示例2: SourceRange
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* Creates a new {@code SourceRange} that corresponds to the given JSONObject.
*
* @param range JSONObject describing the source range.
*/
SourceRange(JSONObject range) {
if (range.containsKey("start")) { // NOI18N
start = ((Number)range.get("start")).intValue(); // NOI18N
end = ((Number)range.get("end")).intValue(); // NOI18N
} else {
start = end = -1;
}
if (range.containsKey("startLine")) { // NOI18N
startLine = ((Number)range.get("startLine")).intValue(); // NOI18N
startColumn = ((Number)range.get("startColumn")).intValue(); // NOI18N
endLine = ((Number)range.get("endLine")).intValue(); // NOI18N
endColumn = ((Number)range.get("endColumn")).intValue(); // NOI18N
} else {
startLine = startColumn = endLine = endColumn = -1;
}
}
示例3: addActivityEntry
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* Generates an activity entry for the link
*/
protected void addActivityEntry(String event, LinkInfo link, SiteInfo site,
WebScriptRequest req, JSONObject json)
{
// What page is this for?
String page = req.getParameter("page");
if (page == null && json != null)
{
if (json.containsKey("page"))
{
page = (String)json.get("page");
}
}
if (page == null)
{
// Default
page = "links";
}
try
{
StringWriter activityJson = new StringWriter();
JSONWriter activity = new JSONWriter(activityJson);
activity.startObject();
activity.writeValue("title", link.getTitle());
activity.writeValue("page", page + "?linkId=" + link.getSystemName());
activity.endObject();
activityService.postActivity(
"org.alfresco.links.link-" + event,
site.getShortName(),
LINKS_SERVICE_ACTIVITY_APP_NAME,
activityJson.toString());
}
catch (Exception e)
{
// Warn, but carry on
logger.warn("Error adding link " + event + " to activities feed", e);
}
}
示例4: exe
import org.json.simple.JSONObject; //導入方法依賴的package包/類
static void exe(String key) {
String data = exe.rmJSVar(exe.read(true, latest.exe.data.FN));
if (data.startsWith("{") && data.endsWith("}")) {
JSONObject res = (JSONObject) JSONValue.parse(data);
if (res.containsKey(key)) {
System.out.println((String) res.get(key));
} else {
LOG.log(Level.INFO, "ERROR:Key '{0}' not exist", key);
}
} else {
System.out.println(data);
}
}
示例5: getSiteInfo
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* returns SiteInfo needed for post activity
* @param req
* @return
*/
protected SiteInfo getSiteInfo(WebScriptRequest req, boolean searchForSiteInJSON)
{
String siteName = req.getParameter(JSON_KEY_SITE);
if (siteName == null && searchForSiteInJSON )
{
JSONObject json = parseJSON(req);
if (json != null){
if (json.containsKey(JSON_KEY_SITE))
{
siteName = (String) json.get(JSON_KEY_SITE);
}
else if (json.containsKey(JSON_KEY_SITE_ID))
{
siteName = (String) json.get(JSON_KEY_SITE_ID);
}
}
}
if (siteName != null)
{
SiteInfo site = siteService.getSite(siteName);
return site;
}
return null;
}
示例6: parseTarget
import org.json.simple.JSONObject; //導入方法依賴的package包/類
public static FavouritesTarget parseTarget(JSONObject jsonObject) throws ParseException
{
FavouritesTarget ret = null;
if(jsonObject.containsKey("site"))
{
JSONObject siteJSON = (JSONObject)jsonObject.get("site");
Site site = SiteImpl.parseSite(siteJSON);
ret = new SiteFavouriteTarget(site);
}
else if(jsonObject.containsKey("file"))
{
JSONObject documentJSON = (JSONObject)jsonObject.get("file");
FavouriteDocument document = FavouriteDocument.parseDocument(documentJSON);
ret = new FileFavouriteTarget(document);
}
else if(jsonObject.containsKey("folder"))
{
JSONObject folderJSON = (JSONObject)jsonObject.get("folder");
FavouriteFolder folder = FavouriteFolder.parseFolder(folderJSON);
ret = new FolderFavouriteTarget(folder);
}
return ret;
}
示例7: fromJson
import org.json.simple.JSONObject; //導入方法依賴的package包/類
public Result fromJson(JSONObject json) {
if(json.containsKey("data")) {
this.data = (JSONObject)json.get("data");
}
this.reason = (String)json.get("reason");
Integer code = Integer.valueOf(((Long)json.get("code")).intValue());
this.errorCode = ErrorCode.valueOf(code, this.reason);
this.messageId = this.data == null?null:(String)this.data.get("id");
if((this.messageId == null || this.messageId.length() == 0) && json.containsKey("trace_id")) {
this.messageId = (String)json.get("trace_id");
}
return this.build();
}
示例8: main
import org.json.simple.JSONObject; //導入方法依賴的package包/類
public static void main(String[] args) {
Monitoring monitoringObj = new Monitoring();
JSONObject req = null;
JSONParser parser = new JSONParser();
while(true){
try {
req = monitoringObj.listenAndConsume("svcQueueMonitoring");
if(req.containsKey("stats")) //Agent sent stats to Monitoring
monitoringObj.updateStats(req);
else if(req.containsKey("killMachineStats"))//ServiceLCMgr asked for all svc stats corresponding to a machine
monitoringObj.reply(monitoringObj.svcList((String)req.get("killMachineStats")));
else if(req.containsKey("removeMachine")){ //ServerLCMgr sent to Monitoring to clear stats
monitoringObj.removeMachine(req);
monitoringObj.reply((JSONObject) parser.parse("{\"result\":\"Machine cleared\"}"));
}
else if(req.containsKey("giveMachineStats")) //ServerLCMgr/any other asked for stats (all stats)
monitoringObj.reply(monitoringObj.getCompleteStats());
else if(req.containsKey("getAllMachineLevelStats")) //LB asked for complete m/c level stats
monitoringObj.reply(monitoringObj.getAllMachineLevelStats());
else if(req.containsKey("getAllSvcLevelStats")) //LB asked for complete svc level stats
monitoringObj.reply(monitoringObj.getAllSvcLevelStats());
else
monitoringObj.doLogging(req,"Monitoring",System.getenv("HOSTNAME"),ManagementFactory.getRuntimeMXBean().getName().split("@")[0],"mainRequestListener","Wrong request type","ERROR");
} catch (Exception e) {
e.printStackTrace();
monitoringObj.doLogging(req,"Monitoring",System.getenv("HOSTNAME"),ManagementFactory.getRuntimeMXBean().getName().split("@")[0],"mainRequestListener","Exception : "+e.getMessage(),"ERROR");
}
}
}
示例9: getOrNull
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* get the value from JSON for given key if exists
* @param json
* @param key
* @return
*/
protected String getOrNull(JSONObject json, String key)
{
if (json != null && json.containsKey(key))
{
return (String) json.get(key);
}
return null;
}
示例10: apply
import org.json.simple.JSONObject; //導入方法依賴的package包/類
@Override
public JSONObject apply(final JSONObject a, final JSONObject b) {
for (final Map.Entry entry : (Set<Map.Entry>) b.entrySet()) {
if (entry.getValue() instanceof JSONObject) {
if (a.containsKey(entry.getKey())) {
final Object object = a.get(entry.getKey());
if (object instanceof JSONArray) {
final JSONObject other = findById((JSONArray) object, ((JSONObject) entry.getValue()));
if (null == other)
((JSONArray) object).add(format((JSONObject) entry.getValue()));
else
apply(other, (JSONObject) entry.getValue());
} else {
final JSONArray array = new JSONArray();
array.add(object);
array.add(format((JSONObject) entry.getValue()));
a.put(entry.getKey(), array);
}
} else
a.put(entry.getKey(), format((JSONObject) entry.getValue()));
} else if (entry.getValue() instanceof List)
a.put(entry.getKey(),
((List) entry.getValue()).size() == 1 ?
((List) entry.getValue()).get(0) : entry.getValue());
else
a.put(entry.getKey(), entry.getValue());
}
return a;
}
示例11: addObjectInformationIntoCollections
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* This function adds <uid,name> of a given object to the collection, and adds the object to the objects File.
*
* @param object the object that will be added
*/
private static void addObjectInformationIntoCollections(JSONObject object){
String uid = object.get("uid").toString();
if (!configuration.getUidToName().containsKey(uid)) {
//If the object doesn't already exist in the collection
String name = "";
if(object.containsKey("name") && object.get("name") != null ){
name = object.get("name").toString();
}
configuration.getUidToName().put(uid, name);
writeJSonObjectToFile(object, configuration.getObjectsWriter(), false);
}
}
示例12: getOrNull
import org.json.simple.JSONObject; //導入方法依賴的package包/類
protected String getOrNull(JSONObject json, String key)
{
if (json.containsKey(key))
{
return (String)json.get(key);
}
return null;
}
示例13: putJSONEntryInMap
import org.json.simple.JSONObject; //導入方法依賴的package包/類
private static void putJSONEntryInMap(JSONObject json,
Map<QName, Serializable> arr, String jsonKey, QName mapKey)
{
if (json.containsKey(jsonKey))
{
arr.put(mapKey, (Serializable)json.get(jsonKey));
}
}
示例14: SpoofedTextContentReader
import org.json.simple.JSONObject; //導入方法依賴的package包/類
/**
* @param url a URL describing the type of text to produce (see class comments)
*/
public SpoofedTextContentReader(String url)
{
super(url);
if (url.length() > 255)
{
throw new IllegalArgumentException("A content URL is limited to 255 characters: " + url);
}
// Split out data part
int index = url.indexOf(ContentStore.PROTOCOL_DELIMITER);
if (index <= 0 || !url.startsWith(FileContentStore.SPOOF_PROTOCOL))
{
throw new RuntimeException("URL not supported by this reader: " + url);
}
String urlData = url.substring(index + 3, url.length());
// Parse URL
try
{
JSONParser parser = new JSONParser();
JSONObject mappedData = (JSONObject) parser.parse(urlData);
String jsonLocale = mappedData.containsKey(KEY_LOCALE) ? (String) mappedData.get(KEY_LOCALE) : Locale.ENGLISH.toString();
String jsonSeed = mappedData.containsKey(KEY_SEED) ? (String) mappedData.get(KEY_SEED) : "0";
String jsonSize = mappedData.containsKey(KEY_SIZE) ? (String) mappedData.get(KEY_SIZE) : "1024";
JSONArray jsonWords = mappedData.containsKey(KEY_WORDS) ? (JSONArray) mappedData.get(KEY_WORDS) : new JSONArray();
// Get the text generator
Locale locale = new Locale(jsonLocale);
seed = Long.valueOf(jsonSeed);
size = Long.valueOf(jsonSize);
words = new String[jsonWords.size()];
for (int i = 0; i < words.length; i++)
{
words[i] = (String) jsonWords.get(i);
}
this.textGenerator = SpoofedTextContentReader.getTextGenerator(locale);
// Set the base class storage for external information
super.setLocale(locale);
super.setEncoding("UTF-8");
super.setMimetype(MimetypeMap.MIMETYPE_TEXT_PLAIN);
}
catch (Exception e)
{
throw new RuntimeException("Unable to interpret URL: " + url, e);
}
}
示例15: getDuration
import org.json.simple.JSONObject; //導入方法依賴的package包/類
public static long getDuration(final MapLocation source, final MapLocation target, final boolean walkingMode) {
final JSONObject $ = getInnerJSON(createURL(source, target, walkingMode));
return !$.containsKey("duration") || !((JSONObject) $.get("duration")).containsKey("value") ? Integer.MAX_VALUE
: $ != null ? (long) ((JSONObject) $.get("duration")).get("value") : 0;
}