本文整理汇总了C++中JSONArray::length方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONArray::length方法的具体用法?C++ JSONArray::length怎么用?C++ JSONArray::length使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONArray
的用法示例。
在下文中一共展示了JSONArray::length方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseCategoryDefinition
void EntityIdentifier::parseCategoryDefinition(JSONObject *data, int packID) {
QString category;
if (data->has("category"))
category = data->at("category")->asString();
else
category = "Unknown";
QColor catcolor;
if (data->has("catcolor")) {
QString colorname = data->at("catcolor")->asString();
catcolor.setNamedColor(colorname);
assert(catcolor.isValid());
} else { // use hashed by name instead
quint32 hue = qHash(category);
catcolor.setHsv(hue % 360, 255, 255);
}
addCategory(qMakePair(category, catcolor));
if (data->has("entity")) {
JSONArray *entities = dynamic_cast<JSONArray *>(data->at("entity"));
int len = entities->length();
for (int e = 0; e < len; e++)
parseEntityDefinition(dynamic_cast<JSONObject *>(entities->at(e)),
category, catcolor, packID);
}
}
示例2: parseEntityDefinition
void EntityIdentifier::parseEntityDefinition(JSONObject *entity,
QString const &category,
QColor catcolor, int packID) {
QString id("unknown");
if (entity->has("id"))
id = entity->at("id")->asString().toLower();
if (entity->has("catcolor")) {
QString colorname = entity->at("catcolor")->asString();
catcolor.setNamedColor(colorname);
assert(catcolor.isValid());
}
QColor color;
if (entity->has("color")) {
QString colorname = entity->at("color")->asString();
color.setNamedColor(colorname);
assert(color.isValid());
} else { // use hashed by name instead
quint32 hue = qHash(id);
color.setHsv(hue % 360, 255, 255);
}
QString name;
if (entity->has("name")) {
// use provided name
name = entity->at("name")->asString();
} else {
// or try to build name automatically
// split at underscores
QStringList tokens = id.toLower().replace('_',' ').split(" ");
// make first character uppercase
for (QList<QString>::iterator tokItr = tokens.begin(); tokItr != tokens.end(); ++tokItr) {
(*tokItr) = (*tokItr).at(0).toUpper() + (*tokItr).mid(1);
}
name = tokens.join(" ");
}
// enter entity into manager
TentityMap& map = getMapForPackID(packID);
map.insert(id, EntityInfo(name, category, catcolor, color));
// add duplicates: when new 1.11+ or 1.13+ id definitions are available
// legacy id is stored in own definition element (duplicates automatically)
if (entity->has("idlist")) {
JSONArray *idlist = dynamic_cast<JSONArray *>(entity->at("idlist"));
int len = idlist->length();
for (int j = 0; j < len; j++) {
QString idl = entity->at("idlist")->at(j)->asString().toLower();
map.insert(idl, EntityInfo(name, category, catcolor, color));
}
}
}
示例3: OuyaPlugin_asyncOuyaRequestProducts
void OuyaPlugin_asyncOuyaRequestProducts(const char* productsJson, s3eCallback onSuccess, s3eCallback onFailure, s3eCallback onCancel)
{
IwTrace(ODK, ("ODK_platform: OuyaPlugin_asyncOuyaRequestProducts"));
std::string msg = "OuyaPlugin_asyncOuyaRequestProducts: productsJson=";
msg.append(productsJson);
IwTrace(ODK, (msg.c_str()));
//convert JSON to product id array
JSONArray jsonArray = JSONArray(productsJson);
std::vector<std::string> productIds;
for (int i = 0; i < jsonArray.length(); i++)
{
std::string productId = jsonArray.getString(i);
productIds.push_back(productId);
}
OuyaSDK::CallbackSingleton::GetInstance()->m_callbacksRequestProducts->RegisterCallbacks(onSuccess, onFailure, onCancel);
g_pluginOuya.AsyncOuyaRequestProducts(productIds);
}
示例4: parseDefinition
void FlatteningConverter::parseDefinition(
JSONObject *b,
int *parentID,
int pack) {
// get the ancient block ID
int bid, data(0);
if (parentID == NULL) {
bid = b->at("id")->asNumber();
} else {
bid = *parentID;
data = b->at("data")->asNumber();
bid |= data << 8;
}
// try to translate old block name into new flatname
QString flatname;
if (b->has("name")) {
flatname = "minecraft:" + b->at("name")->asString().toLower().replace(" ", "_");
} else if (parentID != NULL) {
flatname = palette[*parentID].name;
} else {
flatname = "Unknown";
}
// or use provided flatname instead
if (b->has("flatname"))
flatname = b->at("flatname")->asString();
palette[bid].name = flatname;
palette[bid].hid = qHash(palette[bid].name);
if ((parentID == NULL) && (data == 0)) {
// spread main block type for data == 0
for (int d=1; d<16; d++) {
int sid = bid | (d<<8);
palette[sid].name = flatname;
palette[sid].hid = palette[bid].hid;
}
}
// packs[pack].append(block);
// get optional mask value (or guess default)
int mask = 0;
if (b->has("mask")) {
mask = b->at("mask")->asNumber();
} else if (b->has("variants")) {
mask = 0x0f;
}
// recursive parsing of variants (with data)
if (b->has("variants")) {
JSONArray *variants = dynamic_cast<JSONArray *>(b->at("variants"));
int vlen = variants->length();
for (int j = 0; j < vlen; j++) {
parseDefinition(dynamic_cast<JSONObject *>(variants->at(j)), &bid, pack);
}
// spread variants in masked bid
for (int j = vlen; j < 16; j++) {
int id = bid | (j << 8);
int mid = bid | ((j & mask) << 8);
palette[id].name = palette[mid].name;
palette[id].hid = palette[mid].hid;
}
}
}