简体   繁体   中英

jstring to char* in c usage not converting into printable format

I am running a simple JNI program using the Invocation API on z/os with C. The Java program has a simple sayHello() method like this-

public static String sayHello(){
    return "Hello World!!!";
}

the code that calls this method and prints the output is as follows-

jmethodID mid=(*env)->GetStaticMethodID(env,cls2,sHStr,sigVoidString);
 jstring j = (jstring)(*env)->CallStaticObjectMethod(env,cls2, mid);
 const char *str = (*env)->GetStringUTFChars(env, j, NULL);
 printf("%s", str);
 (*env)->ReleaseStringUTFChars(env,j,str);

The output is printed as follows-

..%%?..?.%....

Turning HEX on shows the following which indicates that it is indeed HelloWorld!!!-

46666256766222
85CCF07F2C4111

I have checked few SO posts about the same problems such as this and this and each suggests using GetStringUTFChars which I am using without any success. Is there anything specific to z/os going on here?

在这种情况下,使用__atoe()函数对我有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM