Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用JNI在C中获取jobject的字符串值?_C_Object_Java Native Interface - Fatal编程技术网

如何使用JNI在C中获取jobject的字符串值?

如何使用JNI在C中获取jobject的字符串值?,c,object,java-native-interface,C,Object,Java Native Interface,我的jobject看起来像{“A”,“B”,1},现在我想得到它的字符串值 目前我有以下代码: class clazz = (*env)->FindClass(env, "model/Spieler"); jmethodID midVorname = (*env)->GetMethodID(env, clazz, "getVorname", "()Ljava/lang/String;"); jmethodID midNachname = (*env)->GetMethodID(

我的jobject看起来像
{“A”,“B”,1}
,现在我想得到它的字符串值

目前我有以下代码:

class clazz = (*env)->FindClass(env, "model/Spieler");
jmethodID midVorname = (*env)->GetMethodID(env, clazz, "getVorname", "()Ljava/lang/String;");
jmethodID midNachname = (*env)->GetMethodID(env, clazz, "getNachname", "()Ljava/lang/String;");
jmethodID midTrikotnummer = (*env)->GetMethodID(env, clazz, "getTrikotnummer", "()I");

char vorname[SIZE];
char nachname[SIZE];
int trikotnummer;
jobject newObj;

link = (Spieler*) malloc(sizeof(Spieler));

newObj = (*env)->GetObjectArrayElement(env, arr, i);

trikotnummer = (*env)->CallIntMethod(env, newObj, midTrikotnummer);
对于
Integer
它的工作原理与上面类似,但我不知道如何通过jmethodID获取
字符串
值。

您有什么建议吗?

您可以尝试以下方法:

/* Access the i-th element in the array */
jobject obj  = (*env)->GetObjectArrayElement(env, arr, i);

/* Call the method */
jobject resultString = (*env)->CallObjectMethod(env, obj, /* method ID */ midVorname);

/* Get a C-style string */
const char* str = (*env)->GetStringUTFChars(env, (jstring) resultString, NULL);

/* Use the string ... */

/* Clean up */
(*env)->ReleaseStringUTFChars(env, resultString, str);

您需要在哪个字符编码中输入字符串值?