如何在 jni 中获取 jobject 的最后一个字符?

How to get the last character of a jobject in jni?

我有一个jobject (ts),我想得到它的最后一个字符,然后比较它是否等于0或s(它是数字和字符的混合)。最简单的方法是什么?

jmethodID methodId_ts = env->GetMethodID(s_clazz,"toCharsString","()Ljava/lang/String;");
jobject ts = env->CallObjectMethod(signature,methodId_ts);

只需使用ts.charAt(ts.length()-1):

jclass cls_String = env->GetObjectClass();
jmethodID mid_String_length = env->GetMethodID(cls_String, "length", "()I");
jmethodID mid_String_charAt = env->GetMethodID(cls_String, "charAt", "()C");

jint len = env->CallIntMethod(ts, mid_String_length);
jchar c  = env->CallCharMethod(ts, mid_String_charAt, len-1);