コード例 #1
0
	JSONObject::JSONObject(const std::string& buffer)
	{
#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Invoke JSONObject(const std::string& buffer)");
#endif
		FindJNI();

		JNIEnv* env = cocos2d::JniHelper::getEnv();

		_instance = env->AllocObject(_jcJsonObject);
		if (_instance)
		{
#if ENABLE_VERBOSE_LOGGING
			__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success allocate JSONObject");
#endif
		}
		else
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to allocate JSONObject");
			return;
		}

		if (!_mConstruct2)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_mConstruct2 is not valid!");
			return;
		}

		jstring arg1 = env->NewStringUTF(buffer.c_str());
		env->CallVoidMethod(_instance, _mConstruct2, arg1);

		if (env->ExceptionCheck())
		{
			env->ExceptionDescribe();
			env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to construct JSONObject");
			return;
		}

#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success constructed JSONObject");
#endif
		env->DeleteLocalRef(arg1);
	}
コード例 #2
0
	JSONObject::JSONObject()
	{
#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Invoke JSONObject()");
#endif
		FindJNI();

		JNIEnv* env = cocos2d::JniHelper::getEnv();

		jobject localRef = env->AllocObject(_jcJsonObject);
		if (localRef)
		{
#if ENABLE_VERBOSE_LOGGING
			__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success allocate JSONObject");
#endif
			_instance = env->NewGlobalRef(localRef);
			env->DeleteLocalRef(localRef);
		}
		else
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to allocate JSONObject");
			return;
		}

		if (!_mConstruct)
		{
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "_mConstruct is not valid!");
			return;
		}

		env->CallVoidMethod(_instance, _mConstruct);

		if (env->ExceptionCheck())
		{
			env->ExceptionDescribe();
			env->ExceptionClear();
			__android_log_print(ANDROID_LOG_ERROR, LOG_TAG, "Failed to construct JSONObject");
			return;
		}

#if ENABLE_VERBOSE_LOGGING
		__android_log_print(ANDROID_LOG_INFO, LOG_TAG, "Success constructed JSONObject");
#endif
	}