本文整理汇总了Java中org.json.JSONArray.getLong方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.getLong方法的具体用法?Java JSONArray.getLong怎么用?Java JSONArray.getLong使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.getLong方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: fromJSON
import org.json.JSONArray; //导入方法依赖的package包/类
@Override
public void fromJSON(JSONObject object, Database catalog_db) throws JSONException {
JSONArray jsonArr = object.getJSONArray(Members.HISTOGRAM.name());
this.histogram = new long[jsonArr.length()];
this.clear();
for (int i = 0; i < this.histogram.length; i++) {
long delta = jsonArr.getLong(i);
if (delta != NULL_COUNT) this.put(i, delta);
} // FOR
if (object.has(Members.DEBUG.name())) {
if (this.debug_names == null) {
this.debug_names = new TreeMap<Object, String>();
} else {
this.debug_names.clear();
}
JSONObject jsonObj = object.getJSONObject(Members.DEBUG.name());
for (String key : CollectionUtil.iterable(jsonObj.keys())) {
String label = jsonObj.getString(key);
this.debug_names.put(Integer.valueOf(key), label);
}
}
}
示例2: parseTrade
import org.json.JSONArray; //导入方法依赖的package包/类
/**
* Parse message that contains one update - trade
*
* @param market
* @param values
* @return
*/
private ParserResponse parseTrade(Market market, JSONArray values) {
try {
int tradeId = values.getInt(0);
long timestampMs = values.getLong(1);
Decimal amount = new Decimal(values.getDouble(2));
boolean sellSide;
if (amount.isNegative()) {
// Negative amount means "this was a sell-side trade"
amount = amount.negate();
sellSide = true;
} else {
sellSide = false;
}
Decimal price = new Decimal(values.getDouble(3));
Date time = new Date(timestampMs);
Trade trade = new Trade(time, price, amount, sellSide);
market.addTrade(trade);
return null;
} catch (JSONException e) {
Logger.log("Error while parsing JSON msg: " + values);
return shutDownAction("Error in BitFinex update parsing:"
+ e.getMessage());
}
}
示例3: Config
import org.json.JSONArray; //导入方法依赖的package包/类
public Config(Path path) throws IOException, JSONException
{
JSONObject json = new JSONObject(new String(Files.readAllBytes(path)));
JSONArray ownerIds = json.getJSONArray("owner_ids");
this.jagroshId = ownerIds.getLong(0);
this.monitorId = ownerIds.getLong(1);
this.token = json.getString("token");
this.databaseUsername = json.getString("database_username");
this.databasePassword = json.getString("database_password");
this.databasePathname = json.getString("database_pathname");
this.webhookId = json.getLong("webhook_id");
this.webhookToken = json.getString("webhook_token");
this.discordBotsKey = json.optString("discord_bots_key", null);
this.carbonitexKey = json.optString("carbonitex_key", null);
this.discordBotsListKey = json.optString("discord_bots_list_key", null);
}
示例4: execute
import org.json.JSONArray; //导入方法依赖的package包/类
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArray of arguments for the plugin.
* @param callbackContext The callback context used when calling back into JavaScript.
* @return True when the action was valid, false otherwise.
*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("vibrate")) {
this.vibrate(args.getLong(0));
}
else if (action.equals("vibrateWithPattern")) {
JSONArray pattern = args.getJSONArray(0);
int repeat = args.getInt(1);
//add a 0 at the beginning of pattern to align with w3c
long[] patternArray = new long[pattern.length()+1];
patternArray[0] = 0;
for (int i = 0; i < pattern.length(); i++) {
patternArray[i+1] = pattern.getLong(i);
}
this.vibrateWithPattern(patternArray, repeat);
}
else if (action.equals("cancelVibration")) {
this.cancelVibration();
}
else {
return false;
}
// Only alert and confirm are async.
callbackContext.success();
return true;
}
示例5: getLong
import org.json.JSONArray; //导入方法依赖的package包/类
public static long getLong(JSONArray ary, int index, long defaultValue) {
try {
if (ary != null) {
if (ary.length() > index && index > -1) {
return ary.getLong(index);
}
}
} catch (Throwable e) {
DLog.e(e);
}
return defaultValue;
}
示例6: load
import org.json.JSONArray; //导入方法依赖的package包/类
public static Config load(File from) throws IOException {
if(!from.exists()) {
String json = new JSONObject()
.put("prefix", ">>")
.put("token", "<your-token-goes-here>")
.put("nas", true)
.put("owners", new JSONArray())
.put("dbs", new JSONObject()
.put("<dbname>", new JSONObject()
.put("host", "<host>")
.put("port", "<port>")
)
)
.put("commandlog", new JSONObject()
.put("useWebhook", false)
.put("channel", "<channel-id-here>")
.put("webhook", new JSONObject()
.put("id", "<id>")
.put("token", "<token>")
)
)
.put("console", new JSONObject()
.put("useWebhook", false)
.put("channel", "<channel-id-here>")
.put("webhook", new JSONObject()
.put("id", "<id>")
.put("token", "<token>")
)
)
.toString(4);
FileOutputStream fos = new FileOutputStream(from);
Utils.copyData(new ByteArrayInputStream(json.getBytes(Charset.defaultCharset())), fos);
fos.close();
GabrielBot.LOGGER.error("No config found, an empty one has been generated.");
GabrielBot.LOGGER.error("Please fill it with valid data");
System.exit(1);
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try(FileInputStream fis = new FileInputStream(from)) {
Utils.copyData(fis, baos);
}
JSONObject obj = new JSONObject(new String(baos.toByteArray(), Charset.defaultCharset()));
String prefix = obj.getString("prefix");
String token = obj.getString(GabrielBot.DEBUG ? "devtoken" : "token");
String dbotsToken = obj.getString("dbotsToken");
String botsPwToken = obj.getString("botsPwToken");
String musicDisableReason = obj.optString("musicDisableReason", "Sorry, music is currently disabled");
boolean music = obj.getBoolean("music");
boolean nas = obj.getBoolean("nas");
long[] owners;
{
JSONArray o = obj.getJSONArray("owners");
owners = new long[o.length()];
for(int i = 0; i < owners.length; i++) {
owners[i] = o.getLong(i);
}
}
Map<String, DBInfo> dbs = new HashMap<>();
{
JSONObject d = obj.getJSONObject("dbs");
for(String name : d.keySet()) {
JSONObject db = d.getJSONObject(name);
dbs.put(name, new DBInfo(db.getString("host"), db.getInt("port")));
}
}
String webhookId = obj.getString("consoleWebhookId");
String webhookToken = obj.getString("consoleWebhookToken");
String rmqHost = obj.getString("rmqHost");
int rmqPort = obj.getInt("rmqPort");
String rmqUsername = obj.getString("rmqUsername");
String rmqPassword = obj.getString("rmqPassword");
String lavalinkHost = obj.getString("lavalinkHost");
int lavalinkPort = obj.getInt("lavalinkPort");
String lavalinkPassword = obj.getString("lavalinkPassword");
return new Config(prefix, token, dbotsToken, botsPwToken, musicDisableReason, music, nas, owners, dbs, webhookId, webhookToken, rmqHost, rmqPort, rmqUsername, rmqPassword, lavalinkHost, lavalinkPort, lavalinkPassword);
}