本文整理了Java中org.json.JSONObject.getBoolean()
方法的一些代码示例,展示了JSONObject.getBoolean()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.getBoolean()
方法的具体详情如下:
包路径:org.json.JSONObject
类名称:JSONObject
方法名:getBoolean
[英]Returns the value mapped by name if it exists and is a boolean or can be coerced to a boolean.
[中]返回按名称映射的值(如果该值存在且为布尔值或可以强制为布尔值)。
代码示例来源:origin: avjinder/Minimal-Todo
public ToDoItem(JSONObject jsonObject) throws JSONException {
mToDoText = jsonObject.getString(TODOTEXT);
mToDoDescription = jsonObject.getString(TODODESCRIPTION);
mHasReminder = jsonObject.getBoolean(TODOREMINDER);
mTodoColor = jsonObject.getInt(TODOCOLOR);
mTodoIdentifier = UUID.fromString(jsonObject.getString(TODOIDENTIFIER));
// if(jsonObject.has(TODOLASTEDITED)){
// mLastEdited = new Date(jsonObject.getLong(TODOLASTEDITED));
// }
if (jsonObject.has(TODODATE)) {
mToDoDate = new Date(jsonObject.getLong(TODODATE));
}
}
代码示例来源:origin: apache/hive
private String processResponse(HttpURLConnection connection) throws IOException {
InputStream stream = connection.getInputStream();
if (stream == null) {
throw new IOException(handleUnexpectedStatusCode(
connection, HttpStatus.SC_OK, "No input on successful API call"));
}
String jsonStr = IOUtils.toString(stream);
try {
JSONObject obj = new JSONObject(jsonStr);
boolean result = obj.getBoolean("allowed");
if (result) return null;
String diag = obj.getString("diagnostics");
return diag == null ? "" : diag;
} catch (JSONException ex) {
LOG.error("Couldn't parse " + jsonStr, ex);
throw ex;
}
}
代码示例来源:origin: cSploit/android
private void fetchReleases() throws IOException, JSONException {
JSONArray releases;
JSONObject release;
boolean found;
releases = new JSONArray(
new String(RemoteReader.fetch(
String.format(RELEASES_URL, username, project)
))
);
mReleases = new JSONArray();
found = false;
for(int i=0;i<releases.length();i++) {
release = releases.getJSONObject(i);
if(release.getBoolean("draft") || release.getBoolean("prerelease"))
continue;
if(mTagFilter != null) {
String tag = release.getString("tag_name");
if(!tag.matches(mTagFilter))
continue;
}
if(!found) {
mLastRelease = release;
found = true;
}
mReleases.put(release);
}
}
代码示例来源:origin: RipMeApp/ripme
private List<String> getPostsFromSinglePage(JSONObject json) {
List<String> imageURLs = new ArrayList<>();
JSONArray datas;
if (json.getJSONObject("entry_data").getJSONArray("PostPage")
.getJSONObject(0).getJSONObject("graphql").getJSONObject("shortcode_media")
.has("edge_sidecar_to_children")) {
datas = json.getJSONObject("entry_data").getJSONArray("PostPage")
.getJSONObject(0).getJSONObject("graphql").getJSONObject("shortcode_media")
.getJSONObject("edge_sidecar_to_children").getJSONArray("edges");
for (int i = 0; i < datas.length(); i++) {
JSONObject data = (JSONObject) datas.get(i);
data = data.getJSONObject("node");
if (data.has("is_video") && data.getBoolean("is_video")) {
imageURLs.add(data.getString("video_url"));
} else {
imageURLs.add(data.getString("display_url"));
}
}
} else {
JSONObject data = json.getJSONObject("entry_data").getJSONArray("PostPage")
.getJSONObject(0).getJSONObject("graphql").getJSONObject("shortcode_media");
if (data.getBoolean("is_video")) {
imageURLs.add(data.getString("video_url"));
} else {
imageURLs.add(data.getString("display_url"));
}
}
return imageURLs;
}
代码示例来源:origin: facebook/facebook-android-sdk
private synchronized static JSONObject parseAppGateKeepersFromJSON(
final String applicationId,
JSONObject gateKeepersJSON) {
JSONObject result;
if (fetchedAppGateKeepers.containsKey(applicationId)) {
result = fetchedAppGateKeepers.get(applicationId);
} else {
result = new JSONObject();
}
JSONArray arr = gateKeepersJSON.optJSONArray(APPLICATION_GRAPH_DATA);
JSONObject gateKeepers = null;
if (arr != null) {
gateKeepers = arr.optJSONObject(0);
}
// If there does exist a valid JSON object in arr, initialize result with this JSON object
if (gateKeepers != null && gateKeepers.optJSONArray(APPLICATION_GATEKEEPER_FIELD) != null) {
JSONArray data = gateKeepers.optJSONArray(APPLICATION_GATEKEEPER_FIELD);
for (int i = 0; i < data.length(); i++) {
try {
JSONObject gk = data.getJSONObject(i);
result.put(gk.getString("key"), gk.getBoolean("value"));
} catch (JSONException je) {
Utility.logd(Utility.LOG_TAG, je);
}
}
}
fetchedAppGateKeepers.put(applicationId, result);
return result;
}
代码示例来源:origin: vdurmont/emoji-java
protected static Emoji buildEmojiFromJSON(
JSONObject json
) throws UnsupportedEncodingException {
if (!json.has("emoji")) {
return null;
}
byte[] bytes = json.getString("emoji").getBytes("UTF-8");
String description = null;
if (json.has("description")) {
description = json.getString("description");
}
boolean supportsFitzpatrick = false;
if (json.has("supports_fitzpatrick")) {
supportsFitzpatrick = json.getBoolean("supports_fitzpatrick");
}
List<String> aliases = jsonArrayToStringList(json.getJSONArray("aliases"));
List<String> tags = jsonArrayToStringList(json.getJSONArray("tags"));
return new Emoji(description, supportsFitzpatrick, aliases, tags, bytes);
}
代码示例来源:origin: facebook/facebook-android-sdk
String sku = purchaseJson.getString("productId");
boolean oldAutoRenewing = oldPurchaseJson.getBoolean("autoRenewing");
boolean newAutoRenewing = purchaseJson.getBoolean("autoRenewing");
代码示例来源:origin: AltBeacon/android-beacon-library
private void buildModelMap(String jsonString) throws JSONException {
HashMap<AndroidModel, DistanceCalculator> map = new HashMap<AndroidModel, DistanceCalculator>();
JSONObject jsonObject = new JSONObject(jsonString);
JSONArray array = jsonObject.getJSONArray("models");
for (int i = 0; i < array.length(); i++) {
JSONObject modelObject = array.getJSONObject(i);
boolean defaultFlag = false;
if (modelObject.has("default")) {
defaultFlag = modelObject.getBoolean("default");
}
Double coefficient1 = modelObject.getDouble("coefficient1");
Double coefficient2 = modelObject.getDouble("coefficient2");
Double coefficient3 = modelObject.getDouble("coefficient3");
String version = modelObject.getString("version");
String buildNumber = modelObject.getString("build_number");
String model = modelObject.getString("model");
String manufacturer = modelObject.getString("manufacturer");
CurveFittedDistanceCalculator distanceCalculator =
new CurveFittedDistanceCalculator(coefficient1,coefficient2,coefficient3);
AndroidModel androidModel = new AndroidModel(version, buildNumber, model, manufacturer);
map.put(androidModel, distanceCalculator);
if (defaultFlag) {
mDefaultModel = androidModel;
}
}
mModelMap = map;
}
代码示例来源:origin: RipMeApp/ripme
private void parseJsonChild(JSONObject child) {
String kind = child.getString("kind");
JSONObject data = child.getJSONObject("data");
if (kind.equals("t1")) {
// Comment
handleBody(data.getString("body"), data.getString("id"), "");
}
else if (kind.equals("t3")) {
// post
if (data.getBoolean("is_self")) {
// TODO Parse self text
handleBody(data.getString("selftext"), data.getString("id"), data.getString("title"));
} else {
// Get link
handleURL(data.getString("url"), data.getString("id"), data.getString("title"));
}
if (data.has("replies") && data.get("replies") instanceof JSONObject) {
JSONArray replies = data.getJSONObject("replies")
.getJSONObject("data")
.getJSONArray("children");
for (int i = 0; i < replies.length(); i++) {
parseJsonChild(replies.getJSONObject(i));
}
}
}
}
代码示例来源:origin: ankidroid/Anki-Android
String type = mCol.getConf().getString("sortType");
String sort = null;
if (type.startsWith("note")) {
boolean sortBackwards = mCol.getConf().getBoolean("sortBackwards");
return new Pair<>(" ORDER BY " + sort, sortBackwards);
} catch (JSONException e) {
代码示例来源:origin: ankidroid/Anki-Android
mOptions = mCol.getDecks().confForDid(mDeck.getLong("id"));
mValues.put("name", mDeck.getString("name"));
mValues.put("desc", mDeck.getString("desc"));
mValues.put("deckConf", mDeck.getString("conf"));
mValues.put("maxAnswerTime", mOptions.getString("maxTaken"));
mValues.put("showAnswerTimer", Boolean.toString(mOptions.getInt("timer") == 1));
mValues.put("autoPlayAudio", Boolean.toString(mOptions.getBoolean("autoplay")));
mValues.put("replayQuestion", Boolean.toString(mOptions.optBoolean("replayq", true)));
final JSONArray reminderTime = reminder.getJSONArray("time");
mValues.put("reminderEnabled", Boolean.toString(reminder.getBoolean("enabled")));
mValues.put("reminderTime", String.format("%1$02d:%2$02d", reminderTime.get(0), reminderTime.get(1)));
} else {
代码示例来源:origin: RipMeApp/ripme
Map<String, String> dataMap = new HashMap<>();
for (String key : JSONObject.getNames(dataObject)) {
dataMap.put(key, dataObject.getString(key));
if (jsonResopnse.getBoolean("success")) {
if (jsonResopnse.getJSONObject("sources").getString(key).contains("hentaidude.com")) {
return jsonResopnse.getJSONObject("sources").getString(key);
代码示例来源:origin: RipMeApp/ripme
rhx_gis = json.getString("rhx_gis");
userID = profilePage.getJSONObject(0).getString("logging_page_id").replaceAll("profilePage_", "");
datas = json.getJSONObject("entry_data").getJSONArray("ProfilePage").getJSONObject(0)
.getJSONObject("graphql").getJSONObject("user")
if (data.getString("__typename").equals("GraphSidecar")) {
try {
Document slideShowDoc = Http.url(new URL("https://www.instagram.com/p/" + data.getString("shortcode"))).get();
if (!data.getBoolean("is_video")) {
if (imageURLs.isEmpty()) {
代码示例来源:origin: facebook/facebook-android-sdk
JSONObject json = new JSONObject(jsonString);
String valueType = json.getString(JSON_VALUE_TYPE);
bundle.putBoolean(key, json.getBoolean(JSON_VALUE));
} else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) {
JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
String charString = json.getString(JSON_VALUE);
if (charString != null && charString.length() == 1) {
bundle.putChar(key, charString.charAt(0));
bundle.putString(key, json.getString(JSON_VALUE));
} else if (valueType.equals(TYPE_STRING_LIST)) {
JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
代码示例来源:origin: ankidroid/Anki-Android
mUpdate.put(name, presetValues.getBoolean(name));
mValues.put(name, Boolean.toString(presetValues.getBoolean(name)));
} else {
mUpdate.put(name, presetValues.getString(name));
mValues.put(name, presetValues.getString(name));
代码示例来源:origin: avjinder/Minimal-Todo
/**
* Ensure we can marshall ToDoItem objects to Json
*/
public void testObjectMarshallingToJson() {
ToDoItem toDoItem = getToDoItem(REMINDER_ON);
try {
JSONObject json = toDoItem.toJSON();
assertEquals(TEXT_BODY, json.getString("todotext"));
assertEquals(REMINDER_ON, json.getBoolean("todoreminder"));
assertEquals(String.valueOf(CURRENT_DATE.getTime()), json.getString("tododate"));
} catch (JSONException e) {
fail("Exception thrown during test execution: " + e.getMessage());
}
}
代码示例来源:origin: facebook/facebook-android-sdk
assertNotNull(json);
assertEquals(true, json.getBoolean("boolValue"));
assertEquals(7, json.getInt("intValue"));
assertEquals(5000000000l, json.getLong("longValue"));
assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA);
assertEquals("hello world", json.getString("stringValue"));
assertEquals(1, innerJson.getInt("inner"));
innerJson = innerJson.getJSONObject("nested bundle");
assertEquals("2", innerJson.getString("inner"));
代码示例来源:origin: apache/geode
testObject.getW_bool().booleanValue(), jsonObject.getBoolean(testObject.getW_boolFN()));
Assert.assertEquals("VerifyPdxInstanceToJson: Float type values are not matched",
testObject.getW_double().doubleValue(), jsonObject.getDouble(testObject.getW_doubleFN()),
testObject.getM_empByCity().get("Ahmedabad").get(0).getFname(),
jsonObject.getJSONObject(testObject.getM_empByCityFN()).getJSONArray("Ahmedabad")
.getJSONObject(0).getString("fname"));
testObject.getDay().toString(), jsonObject.getString(testObject.getDayFN()));
代码示例来源:origin: ankidroid/Anki-Android
JSONObject rMeta = new JSONObject(mServer.stream2String(ret.getEntity().getContent()));
mCol.log("rmeta", rMeta);
mSyncMsg = rMeta.getString("msg");
if (!rMeta.getBoolean("cont")) {
Timber.i("Sync: applying chunked data");
applyChunk(chunk);
if (chunk.getBoolean("done")) {
break;
Timber.i("Sync: sending chunked data");
mServer.applyChunk(sech);
if (chunk.getBoolean("done")) {
break;
代码示例来源:origin: stackoverflow.com
String json = IOUtils.toString(response.getEntity().getContent());
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
log.info("the id is {}", object.getInt("id"));
log.info("the insertDate is {}", object.getString("insertDate"));
log.info("read is {}", object.getBoolean("read"));
log.info("the site is {}", object.getString("site"));
log.info("the Email is {}", object.getString("Email"));
log.info("the location is {}", object.getString("location"));
}
内容来源于网络,如有侵权,请联系作者删除!