JNI。如何从jobject获取jstring并将其转换为char *

到目前为止,这就是我所拥有的:我传递一个具有2个字段的对象:String和Integer作为参数,并且我想发送信息以在C部分中对其进行处理,这在当时并不重要…我抱怨在jstring声明

JNIEXPORT jint JNICALL Java_Tier3_NativeMethods_totalPalletsIn(

JNIEnv *env, jclass cls, jobject stat) {

jclass staticsitcs = (*env)->GetObjectClass(env, stat);

// Here I try to get it using the ID

jfieldID idDate = (*env)->GetFieldID(env, staticsitcs, "date", "S");

jstring dateString = (jstring)(*env)->GetStringRegion(env, stat, idDate);

// Here converting whatever I get in jstring to char*

char* date = (*env)->GetStringUTFChars(env,dateString,0);

// Getting the 2nd field from the object

jfieldID idNumber = (*env)->GetFieldID(env, staticsitcs, "amount", "I");

jint amount = (*env)->GetDoubleField(env, stat, idNumber);

// Calling C method

jint totalPallets = checkTotalPalletsIn(date, amount);

(*env)->ReleaseStringUTFChars(env, dateString, date);

return totalPallets;

}

我想念什么?

回答:

jstring dateString = (jstring)(*env)->GetObjectField(env, stat, idDate);

……然后一切正常。

以上是 JNI。如何从jobject获取jstring并将其转换为char * 的全部内容, 来源链接: utcz.com/qa/430547.html

回到顶部