示例#1
0
jobject rho_cast_helper<jobject, CJSONEntry>::operator ()(JNIEnv *env, const CJSONEntry& jsonEntry)
{
    if(jsonEntry.isEmpty() || jsonEntry.isNull()) {
        return 0;
    }
    if (!initConvertor(env))
    {
        return 0;
    }
    if(jsonEntry.isString())
    {
        RAWTRACE("Convert to String object");
        return rho_cast<jstring>(env, jsonEntry.getString());
    }
    if(jsonEntry.isArray())
    {
        RAWTRACE("Convert to Collection object");
        return convertJsonEntryToJavaCollection(jsonEntry);
    }
    if(jsonEntry.isObject())
    {
        RAWTRACE("Convert to Map object");
        return convertJsonEntryToJavaMap(jsonEntry);
    }
    if(jsonEntry.isBoolean())
    {
        RAWTRACE("Convert to Boolean object");
        return RhoJniConvertor::getBooleanObject(jsonEntry.getBoolean());
    }
    if(jsonEntry.isInteger())
    {
        RAWTRACE("Convert to Integer object");
        return RhoJniConvertor::getIntegerObject(jsonEntry.getInt());
    }
    if(jsonEntry.isFloat())
    {
        RAWTRACE("Convert to Double object");
        return RhoJniConvertor::getDoubleObject(jsonEntry.getDouble());
    }

    RAWTRACE("Convert to null");
    return 0;
}
示例#2
0
jobjectArray rho_cast_helper<jobjectArray, CJSONEntry>::operator ()(JNIEnv *env, const CJSONEntry& jsonEntry)
{
    if (!jsonEntry.isArray())
    {
        return 0;
    }
    if (!initConvertor(env))
    {
        return 0;
    }

    CJSONArray jsonArray(jsonEntry);
    int size = jsonArray.getSize();
    jobjectArray jArray = env->NewObjectArray(size, clsString, 0);

    for(int i = 0; i < size; ++i)
    {
        jhstring jhElement = rho_cast<jstring>(env, jsonArray.getItem(i).getString());
        env->SetObjectArrayElement(jArray, i, jhElement.get());
    }
    return jArray;
}