本文整理汇总了Java中org.json.JSONObject.has方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.has方法的具体用法?Java JSONObject.has怎么用?Java JSONObject.has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.has方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sanitizeMediaStatusMessage
import org.json.JSONObject; //导入方法依赖的package包/类
/**
* Modifies the received MediaStatus message to match the format expected by the client.
*/
private void sanitizeMediaStatusMessage(JSONObject object) throws JSONException {
object.put("sessionId", mSession.getSessionId());
JSONArray mediaStatus = object.getJSONArray("status");
for (int i = 0; i < mediaStatus.length(); ++i) {
JSONObject status = mediaStatus.getJSONObject(i);
status.put("sessionId", mSession.getSessionId());
if (!status.has("supportedMediaCommands")) continue;
JSONArray commands = new JSONArray();
int bitfieldCommands = status.getInt("supportedMediaCommands");
for (int j = 0; j < 4; ++j) {
if ((bitfieldCommands & (1 << j)) != 0) {
commands.put(MEDIA_SUPPORTED_COMMANDS[j]);
}
}
status.put("supportedMediaCommands", commands); // Removes current entry.
}
}
示例2: needPermission
import org.json.JSONObject; //导入方法依赖的package包/类
private boolean needPermission(String nativeURL, int permissionType) throws JSONException {
JSONObject j = requestAllPaths();
ArrayList<String> allowedStorageDirectories = new ArrayList<String>();
allowedStorageDirectories.add(j.getString("applicationStorageDirectory"));
if(j.has("externalApplicationStorageDirectory")) {
allowedStorageDirectories.add(j.getString("externalApplicationStorageDirectory"));
}
if(permissionType == READ && hasReadPermission()) {
return false;
}
else if(permissionType == WRITE && hasWritePermission()) {
return false;
}
// Permission required if the native url lies outside the allowed storage directories
for(String directory : allowedStorageDirectories) {
if(nativeURL.startsWith(directory)) {
return false;
}
}
return true;
}
示例3: onPushMsg
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public boolean onPushMsg(Context context, byte[] msg, Bundle bundle) {
try {
String remoteMessageOrign = new String(msg, "UTF-8");
JSONObject remoteMessage = new JSONObject(remoteMessageOrign);
if(!remoteMessage.has("isAt")) remoteMessage.put("isAt","0");
if(!remoteMessage.has("senderType")) remoteMessage.put("senderType","1");
//SharedPreferences Settings = context.getSharedPreferences(PREF, Context.MODE_PRIVATE);
String tokenSender = mySettings.getString("push_type","GCM");
if(tokenSender.equals("HwPush")) {
Log.d(MYTAG, "华为推送:"+remoteMessageOrign);
MessageUtil.MessageUtilDo(context,remoteMessage.getString("msgId"),remoteMessage.getString("type"),remoteMessage.getString("senderType"),remoteMessage.getString("title"),remoteMessage.getString("message"),remoteMessage.getString("isAt"));
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
示例4: deapplyAura
import org.json.JSONObject; //导入方法依赖的package包/类
public void deapplyAura(JSONObject aura, Player player, int min) {
String auraClass = "";
if (aura.has("class")) {
auraClass = aura.getString("class");
}
if (auraClass.equals("BuffAura")) {
int attackBonus = 0;
int hpBonus = 0;
if (aura.has("attackBonus")) {
attackBonus = aura.getInt("attackBonus");
}
if (aura.has("hpBonus")) {
hpBonus = aura.getInt("hpBonus");
}
System.out.println("ATTACK BONUS:" + attackBonus + ", HEALTH BONUS: " + hpBonus);
game.players.get(game.players.indexOf(player)).board.get(min).setAttack(player.board.get(min).getAttack() - attackBonus);
game.players.get(game.players.indexOf(player)).board.get(min).setMaxHealth(game.players.get(game.players.indexOf(player)).board.get(min).getMaxHealth() - hpBonus);
if (game.players.get(game.players.indexOf(player)).board.get(min).getHealth() <= 0) {
game.players.get(game.players.indexOf(player)).board.get(min).setHealth(1);
}
game.players.get(game.players.indexOf(player)).board.get(min).setHealth(game.players.get(game.players.indexOf(player)).board.get(min).getHealth() - hpBonus);
}
}
示例5: loadServerErrorMsg
import org.json.JSONObject; //导入方法依赖的package包/类
private String loadServerErrorMsg() {
if (responseData == null || responseData.getBody() == null) {
return null;
}
try {
JSONObject jsonObject = new JSONObject(responseData.getBody());
if (jsonObject.has("error_description")) {
return jsonObject.getString("error_description");
} else if (jsonObject.has("errors")) {
List<String> errors = getErrors(jsonObject);
return errors.isEmpty() ? null : ParticleInternalStringUtils.join(errors, '\n');
} else if (jsonObject.has("error")) {
return jsonObject.getString("error");
}
} catch (JSONException e) {
}
return null;
}
示例6: parseDisturbances
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public Disturbance[] parseDisturbances(JSONObject jsonData) throws JSONException {
if (jsonData == null) {
throw new IllegalArgumentException("JSONObject is null");
}
if (!jsonData.has("disturbance")) {
return new Disturbance[0];
}
JSONArray items = jsonData.getJSONArray("disturbance");
Disturbance[] result = new Disturbance[items.length()];
for (int i = 0; i < items.length(); i++) {
result[i] = new Disturbance(i,
timestamp2date(items.getJSONObject(i).getString("timestamp")),
items.getJSONObject(i).getString("title"),
items.getJSONObject(i).getString("description"),
items.getJSONObject(i).getString("link"));
}
return result;
}
示例7: RuntimeConfig
import org.json.JSONObject; //导入方法依赖的package包/类
RuntimeConfig(@NonNull JSONObject json, String url) {
runtime = json;
final String applicationId = Uri.parse(url).getPathSegments().get(1);
final boolean isAssetsExternal = json.has("amazon");
formattedAssetUrl = isAssetsExternal
? json.optString("amazon") + "/apps/" + applicationId + "/assets/%s.png"
: url.replace("runtime", "assets") + "/%s/download";
if (json.length() == 0) {
throw new KolibriException("Runtime config JSON is empty. Cannot construct configuration.");
}
parseStructure();
if (navigation == null || domain == null || scheme == null || styling == null) {
throw new KolibriException("Runtime config JSON is not valid one.");
}
}
示例8: validateJSONWordpack
import org.json.JSONObject; //导入方法依赖的package包/类
public boolean validateJSONWordpack(String text) {
try {
JSONObject jsonData = new JSONObject(text);
if (jsonData.has("from") &&
jsonData.has("to") &&
jsonData.has("pack") &&
jsonData.has("title")) {
if (jsonData.getJSONArray("pack").length()>0) return true;
} else
Log.v("WordLing", "Invalid wordpack format");
} catch (JSONException e) {
Log.v("WordLing", "Error occured when parsing wordpack");
}
return false;
}
示例9: onActivityResult
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == Config.REQUEST_GET_LOCAL_DICTIONARY) {
if (resultCode == RESULT_OK) {
if (data != null && data.getData() != null) {
ContentResolver resolver = getContentResolver();
String fileType = resolver.getType(data.getData());
if (fileType != null) {
if (fileType.startsWith("image")) {
Toast.makeText(this, R.string.settings_extra_words_load_failed, Toast.LENGTH_SHORT).show();
finish();
return;
}
}
String file_path = URI.getAbsolutePath(this, data.getData());
String text = IOMethod.readFile(file_path);
try {
JSONObject jsonObject = new JSONObject(text);
if (jsonObject.has(Config.DEFAULT_EXTRA_WORDS_DATA_NAME)) {
String name = new File(file_path).getName();
String path = Config.DEFAULT_APPLICATION_DATA_DIR + name;
if (IOMethod.writeFile(jsonObject.toString(), path)) {
String newName = Code.unicodeEncode(name) + "-" + Code.getFileMD5String(path);
if (IOMethod.renameFile(path, newName)) {
Toast.makeText(this, R.string.settings_extra_words_load_success, Toast.LENGTH_SHORT).show();
return;
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
Toast.makeText(this, R.string.settings_extra_words_load_failed, Toast.LENGTH_SHORT).show();
}
}
}
super.onActivityResult(requestCode, resultCode, data);
}
示例10: toMap
import org.json.JSONObject; //导入方法依赖的package包/类
private static Map<String, Integer> toMap(JSONObject json) {
if (!json.has("status") || !json.has(JSON_RESULTS)) {
return new HashMap<>();
}
Map<String, Integer> ratings = new HashMap<>();
JSONArray ratingsArray = json.getJSONArray(JSON_RESULTS);
for (Object rating : ratingsArray) {
JSONObject r = (JSONObject) rating;
ratings.put(r.getString("handle"), r.getInt("rating"));
}
return ratings;
}
示例11: dispatchEvent
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public void dispatchEvent(JSONObject json, int sequence) {
Guild guild = (Guild) identity.getGuild(json.getString("id"));
if (json.has("presences")) {
JSONArray presences = json.getJSONArray("presences");
for (int i = 0; i < presences.length(); i++) {
JSONObject presence = presences.getJSONObject(i);
builder.buildPresence(presence, (User) identity.getUser(presence.getJSONObject("user").getString("id"))); // Presences are set automatically
}
}
// Ignore initial guild create event
if (guild == null) {
guild = builder.buildGuild(json);
dispatchEvent(new GuildCreateEvent(identity, sequence, guild));
}
// Request guild members after the guild is built
long memberCount = json.getLong("member_count");
if (memberCount > JCord.GUILD_MEMBERS_LARGE_THRESHOLD) { // Need to request guild members
identity.getGateway().sendRequestMembers(json.getString("id"));
}
}
示例12: fromJSON
import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public void fromJSON(JSONObject json_object, Database catalog_db) throws JSONException {
this.name = json_object.getString("NAME");
this.total_time = json_object.getLong("TIME");
this.invocations = json_object.getInt("INVOCATIONS");
if (json_object.has("HISTORY")) {
this.history = null;
this.enableHistoryTracking();
JSONArray json_arr = json_object.getJSONArray("HISTORY");
for (int i = 0, cnt = json_arr.length(); i < cnt; i++) {
this.history.add(json_arr.getLong(i));
} // FOR
}
}
示例13: findSelectByProperties
import org.json.JSONObject; //导入方法依赖的package包/类
private List<IJavaFXElement> findSelectByProperties(JSONObject o) {
List<IJavaFXElement> r = new ArrayList<>();
if (o.has("select")) {
JSONObject jo = new JSONObject((String) o.get("select"));
JSONArray cell = (JSONArray) jo.get("cell");
JavaFXTreeTableViewCellElement e = new JavaFXTreeTableViewCellElement(this, cell.getString(0),
getTreeTableColumnIndex((TreeTableView<?>) getComponent(), cell.getString(1)));
if (!(boolean) e._makeVisible()) {
return Arrays.asList();
}
r.add(e);
}
return r;
}
示例14: parseLists
import org.json.JSONObject; //导入方法依赖的package包/类
public static ArrayList<Milestone> parseLists(JSONObject object) {
if (!object.has("achieved_milestones")) {
return null;
}
return (ArrayList) new Gson().fromJson(object.optString("achieved_milestones"), new
TypeToken<ArrayList<Milestone>>() {
}.getType());
}
示例15: ArticleListBean
import org.json.JSONObject; //导入方法依赖的package包/类
public ArticleListBean(JSONObject article) {
try {
classid = article.getString("classid");
if (article.has("classname")) {
classname = article.getString("classname");
}
id = article.getString("id");
title = article.getString("title");
befrom = article.getString("befrom");
onclick = article.getString("onclick");
isgood = article.getString("isgood");
istop = article.getString("istop");
firsttitle = article.getString("firsttitle");
isurl = article.getString("isurl");
keyboard = article.getString("keyboard");
if (article.has("titleurl")) {
titleurl = article.getString("titleurl");
}
plnum = article.getString("plnum");
newstime = article.getString("newstime");
titlepic = article.getString("titlepic");
JSONArray morepicArray = article.getJSONArray("morepic");
morepic = new String[morepicArray.length()];
for (int j = 0; j < morepicArray.length(); j++) {
morepic[j] = morepicArray.get(j).toString();
}
} catch (JSONException e) {
e.printStackTrace();
}
}