当前位置: 首页>>代码示例>>Java>>正文


Java JSONObject.containsKey方法代码示例

本文整理汇总了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
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:Style.java

示例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;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:22,代码来源:SourceRange.java

示例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);
   }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:43,代码来源:AbstractLinksWebScript.java

示例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);
    }

}
 
开发者ID:CognizantQAHub,项目名称:Cognizant-Intelligent-Test-Scripter,代码行数:15,代码来源:CLI.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:32,代码来源:AbstractCommentsWebScript.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:28,代码来源:Favourite.java

示例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();
}
 
开发者ID:marlonwang,项目名称:raven,代码行数:16,代码来源:Result.java

示例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");
		}
	}
}
 
开发者ID:hemantverma1,项目名称:ServerlessPlatform,代码行数:31,代码来源:Monitoring.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:15,代码来源:AbstractCommentsWebScript.java

示例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;
}
 
开发者ID:okram,项目名称:mongodb-gremlin,代码行数:31,代码来源:MongoDBQueryStep.java

示例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);
    }
}
 
开发者ID:CheckPoint-APIs-Team,项目名称:ShowPolicyPackage,代码行数:19,代码来源:ShowPackageTool.java

示例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;
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:9,代码来源:AbstractDiscussionWebScript.java

示例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));
     }
}
 
开发者ID:Alfresco,项目名称:alfresco-remote-api,代码行数:9,代码来源:BlogLibJs.java

示例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);
    }
    
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:49,代码来源:SpoofedTextContentReader.java

示例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;
}
 
开发者ID:TechnionYP5777,项目名称:SmartParking,代码行数:6,代码来源:Navigation.java


注:本文中的org.json.simple.JSONObject.containsKey方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。