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


Java JSONObject.opt方法代码示例

本文整理汇总了Java中org.json.JSONObject.opt方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.opt方法的具体用法?Java JSONObject.opt怎么用?Java JSONObject.opt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.opt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: init

import org.json.JSONObject; //导入方法依赖的package包/类
public void init (FirebaseApp firebaseApp) {
	mFirebaseApp = firebaseApp;
	String token = getFirebaseMessagingToken();

	dispatcher =
	new FirebaseJobDispatcher(new GooglePlayDriver(activity.getApplicationContext()));
	dispatcher.cancel("firebase-notify-in-time-UID");

	Utils.d("Firebase Cloud messaging token: " + token);

	// Perform task here..!
	if (KeyValueStorage.getValue("notification_complete_task") != "0") {
		try {
			JSONObject obj =
			new JSONObject(KeyValueStorage.getValue("notification_task_data"));

			Dictionary data = new Dictionary();
			Iterator<String> iterator = obj.keys();

			while (iterator.hasNext()) {
				String key = iterator.next();
				Object value = obj.opt(key);

				if (value != null) {
					data.put(key, value);
				}
			}

			Utils.callScriptCallback(
			KeyValueStorage.getValue("notification_complete_task"),
			"Notification", "TaskComplete", data);

		} catch (JSONException e) {

		}

		KeyValueStorage.setValue("notification_complete_task", "0");
	}
}
 
开发者ID:FrogSquare,项目名称:GodotFireBase,代码行数:40,代码来源:Notification.java

示例2: getChecksFromJson

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Gets a list of connection checks from JSON. If json does not contain a 'check' field
 * null will be returned instead.
 *
 * @param json The JSON to extract the connection checks from.
 * @param checksKey The key for the checks.
 *
 * @return The set of checks or null.
 */
@Nullable
public static String[] getChecksFromJson(JSONObject json, String checksKey) {
    Object checkObj = json.opt(checksKey);
    String[] checks = null;
    if (checkObj == null) {
        // Do nothing, ignore other checks
    } else if (checkObj instanceof JSONArray) {
        JSONArray jsonChecks = (JSONArray) checkObj;
        if (jsonChecks != null) {
            int count = jsonChecks.length();
            checks = new String[count];
            for (int i = 0; i < count; i++) {
                checks[i] = jsonChecks.optString(i);
                if (checks[i] == null) {
                    throw new IllegalArgumentException("Malformatted check array in Input.");
                }
            }
        }
    } else if (checkObj instanceof String) {
        checks = new String[]{(String) checkObj};
    }
    return checks;
}
 
开发者ID:Axe-Ishmael,项目名称:Blockly,代码行数:33,代码来源:Input.java

示例3: loadFromJSON

import org.json.JSONObject; //导入方法依赖的package包/类
private void loadFromJSON(JSONObject json) throws JSONException {
  // Get the status code
  this.statusCode = (String) json.get(JsonTagsZ.STATUS);
  if (JsonTagsZ.STATUS_TRUE.equals(this.statusCode)) {
    this.status = true;
  } else {
    this.status = false;
  }

  if (!status) {
    this.errMsg = (String) json.opt(JsonTagsZ.MESSAGE);
    this.errors = getErrorData(json);
  } else {
    // Load the userId
    this.userId = (String) json.get(JsonTagsZ.USER_ID);
    // Load the kiosk Id
    this.entityId = (String) json.get(JsonTagsZ.KIOSK_ID);
  }
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:20,代码来源:SetupDataOutput.java

示例4: handle

import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public Response handle() throws Exception {
  WebDriverLikeCommand command =
      WebDriverLikeCommand.valueOf(getRequest().getVariableValue(":command"));
  JSONObject payload = JavaxJson.toOrgJson(getRequest().getPayload());

  @SuppressWarnings("unchecked")
  Iterator<String> iter = payload.keys();
  while (iter.hasNext()) {
    String key = iter.next();
    Object value = payload.opt(key);
    getSession().configure(command).set(key, value);
  }

  Response resp = new Response();
  resp.setSessionId(getSession().getSessionId());
  resp.setStatus(0);
  resp.setValue(new JSONObject());
  return resp;

}
 
开发者ID:google,项目名称:devtools-driver,代码行数:22,代码来源:SetConfigurationHandler.java

示例5: parseJson_should_return_correct_testclass_object

import org.json.JSONObject; //导入方法依赖的package包/类
@Test
public void parseJson_should_return_correct_testclass_object()
        throws StockException {
    String jsonString = "{  \"id\":1234,  \"description\":\"Sample description\", \"property\": {     \"key\": \"test key\"  },  \"array\":[3,5,9,10],  \"required\":true,  \"precision\":10.12}";
    JSONObject testObj = new JSONObject(jsonString);
    TestClass parsedObj = (TestClass) JsonUtils.parseJson(TestClass.class,
            jsonString);

    Assert.assertEquals(testObj.opt("id"), checkNull(parsedObj.getId()));
    Assert.assertEquals(testObj.opt("description"),
            checkNull(parsedObj.getDescription()));
    Assert.assertEquals(testObj.opt("required"),
            checkNull(parsedObj.getRequired()));

    if (!testObj.isNull("array")) {
        JSONArray objArray = (JSONArray) testObj.opt("array");
        ArrayList<Integer> parsedArray = parsedObj.getArray();
        for (int i = 0; i < objArray.length(); i++) {
            Assert.assertTrue(parsedArray.contains(objArray.get(i)));
        }
    }
    if (!testObj.isNull("property")) {
        JSONObject obj = (JSONObject) testObj.opt("property");
        Assert.assertNotNull(parsedObj.getProperty());
        Assert.assertEquals(checkNull(obj.opt("key")),
                parsedObj.getProperty().getKey());

    }
}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:30,代码来源:JsonUtilsTest.java

示例6: jsonObjectContainsValue

import org.json.JSONObject; //导入方法依赖的package包/类
static boolean jsonObjectContainsValue(JSONObject jsonObject, Object value) {
    @SuppressWarnings("unchecked")
    Iterator<String> keys = (Iterator<String>) jsonObject.keys();
    while (keys.hasNext()) {
        Object thisValue = jsonObject.opt(keys.next());
        if (thisValue != null && thisValue.equals(value)) {
            return true;
        }
    }
    return false;
}
 
开发者ID:MobileDev418,项目名称:chat-sdk-android-push-firebase,代码行数:12,代码来源:JsonUtil.java

示例7: getParameterValueDict

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Convert a JSONObject into a HashMap
 */
static HashMap<String, ParameterValue> getParameterValueDict(JSONObject json) {
    Iterator<String> keys = json.keys();
    HashMap<String, ParameterValue> dict = new HashMap<>();
    while (keys.hasNext()) {
        String key = keys.next();
        Object p = json.opt(key);
        if (p != null) {
            ParameterValue param = new ParameterValue(p);
            dict.put(key, param);
        }
    }
    return dict;
}
 
开发者ID:pullstring,项目名称:pullstring-android,代码行数:17,代码来源:ParameterValue.java

示例8: FetchUpdateOptions

import org.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public FetchUpdateOptions(final JSONObject json) throws JSONException {
    if (json == null) {
        throw new JSONException("Can't parse null json object");
    }

    this.configURL = json.optString(CONFIG_URL_JSON_KEY, null);

    final JSONObject requestHeadersJson = (JSONObject) json.opt(REQUEST_HEADERS_JSON_KEY);
    if (requestHeadersJson != null) {
        this.requestHeaders = JSONUtils.toFlatStringMap(requestHeadersJson);
    }
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:14,代码来源:FetchUpdateOptions.java

示例9: getCategory

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Gets a category by the specified request.
 * <p>
 * Renders the response with a json object, for example,
 * 
 * <pre>
 * {
 *     "sc": boolean,
 *     "category": {
 *         "oId": "",
 *         "categoryTitle": "",
 *         "categoryURI": "",
 *         ....
 *     }
 * }
 * </pre>
 * </p>
 *
 * @param request
 *            the specified http servlet request
 * @param response
 *            the specified http servlet response
 * @param context
 *            the specified http request context
 * @throws Exception
 *             exception
 */
@RequestMapping(value = "/console/category/*", method = RequestMethod.GET)
public void getCategory(final HttpServletRequest request, final HttpServletResponse response) throws Exception {
	if (!userQueryService.isAdminLoggedIn(request)) {
		response.sendError(HttpServletResponse.SC_FORBIDDEN);
		return;
	}

	final JSONRenderer renderer = new JSONRenderer();

	try {
		final String requestURI = request.getRequestURI();
		final String categoryId = requestURI.substring((Latkes.getContextPath() + "/console/category/").length());

		final JSONObject result = categoryQueryService.getCategory(categoryId);
		if (null == result) {
			renderer.setJSONObject(QueryResults.defaultResult());
			renderer.render(request, response);
			return;
		}

		final StringBuilder tagBuilder = new StringBuilder();
		final List<JSONObject> tags = (List<JSONObject>) result.opt(Category.CATEGORY_T_TAGS);
		for (final JSONObject tag : tags) {
			tagBuilder.append(tag.optString(Tag.TAG_TITLE)).append(",");
		}
		tagBuilder.deleteCharAt(tagBuilder.length() - 1);
		result.put(Category.CATEGORY_T_TAGS, tagBuilder.toString());

		renderer.setJSONObject(result);
		result.put(Keys.STATUS_CODE, true);
	} catch (final ServiceException e) {
		logger.error(e.getMessage(), e);

		final JSONObject jsonObject = QueryResults.defaultResult();
		renderer.setJSONObject(jsonObject);
		jsonObject.put(Keys.MSG, langPropsService.get("getFailLabel"));
	}
	renderer.render(request, response);
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:67,代码来源:CategoryConsole.java

示例10: getPreviousArticle

import org.json.JSONObject; //导入方法依赖的package包/类
public JSONObject getPreviousArticle(final String articleId) throws RepositoryException {
	final JSONObject currentArticle = get(articleId);
	final Date currentArticleCreateDate = (Date) currentArticle.opt(Article.ARTICLE_CREATE_DATE);

	final Query query = new Query()
			.setFilter(CompositeFilterOperator.and(
					new PropertyFilter(Article.ARTICLE_CREATE_DATE, FilterOperator.LESS_THAN,
							currentArticleCreateDate),
					new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true)))
			.addSort(Article.ARTICLE_CREATE_DATE, SortDirection.DESCENDING).setCurrentPageNum(1).setPageSize(1)
			.setPageCount(1).addProjection(Article.ARTICLE_TITLE, String.class)
			.addProjection(Article.ARTICLE_PERMALINK, String.class)
			.addProjection(Article.ARTICLE_ABSTRACT, String.class);

	final JSONObject result = get(query);
	final JSONArray array = result.optJSONArray(Keys.RESULTS);

	if (1 != array.length()) {
		return null;
	}

	final JSONObject ret = new JSONObject();
	final JSONObject article = array.optJSONObject(0);

	try {
		ret.put(Article.ARTICLE_TITLE, article.getString(Article.ARTICLE_TITLE));
		ret.put(Article.ARTICLE_PERMALINK, article.getString(Article.ARTICLE_PERMALINK));
		ret.put(Article.ARTICLE_ABSTRACT, article.getString((Article.ARTICLE_ABSTRACT)));
	} catch (final JSONException e) {
		throw new RepositoryException(e);
	}

	return ret;
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:35,代码来源:ArticleDao.java

示例11: getErrorData

import org.json.JSONObject; //导入方法依赖的package包/类
private Vector getErrorData(JSONObject json) throws JSONException {
  Vector errors = new Vector();
  JSONArray array = (JSONArray) json.opt(JsonTagsZ.ERRORS);
  for (int i = 0; i < array.length(); i++) {
    String e = (String) array.get(i);
    // Add to vector
    errors.addElement(e.toString());
  }
  return errors;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:11,代码来源:SetupDataOutput.java

示例12: getValue

import org.json.JSONObject; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") public <T> T getValue(String section, String property, T defaultValue) {
    JSONObject oSection = getSection(section);
    Object value = oSection.opt(property);
    if (value == null) {
        return defaultValue;
    }
    return (T) value;
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:9,代码来源:AbstractPreferences.java

示例13: createAnimatablePathOrSplitDimensionPath

import org.json.JSONObject; //导入方法依赖的package包/类
static AnimatableValue<PointF> createAnimatablePathOrSplitDimensionPath(
    JSONObject json, LottieComposition composition) {
  if (json.has("k")) {
    return new AnimatablePathValue(json.opt("k"), composition);
  } else {
    return new AnimatableSplitDimensionPathValue(
        AnimatableFloatValue.Factory.newInstance(json.optJSONObject("x"), composition),
        AnimatableFloatValue.Factory.newInstance(json.optJSONObject("y"), composition));
  }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:11,代码来源:AnimatablePathValue.java

示例14: jsonObjectEntrySet

import org.json.JSONObject; //导入方法依赖的package包/类
static Set<Map.Entry<String, Object>> jsonObjectEntrySet(JSONObject jsonObject) {
    HashSet<Map.Entry<String, Object>> result = new HashSet<Map.Entry<String, Object>>();

    @SuppressWarnings("unchecked")
    Iterator<String> keys = (Iterator<String>) jsonObject.keys();
    while (keys.hasNext()) {
        String key = keys.next();
        Object value = jsonObject.opt(key);
        result.add(new JSONObjectEntry(key, value));
    }

    return result;
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:14,代码来源:JsonUtil.java

示例15: getErrorData

import org.json.JSONObject; //导入方法依赖的package包/类
private Vector getErrorData(JSONObject json) throws JSONException {
  Vector errMsgs = new Vector();
  JSONArray array = (JSONArray) json.opt(JsonTagsZ.ERRORS);
  if (array != null) {
    for (int i = 0; i < array.length(); i++) {
      String e = (String) array.get(i);
      // Add to vector
      errMsgs.addElement(e.toString());
    }
  }
  return errMsgs;
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:13,代码来源:BasicOutput.java


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