简体   繁体   English

从j用法到char *的jstring不会转换为可打印格式

[英]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- 我正在z / os和C上使用Invocation API运行一个简单的JNI程序。Java程序具有一个简单的sayHello()方法,如下所示:

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!!!- 开启十六进制会显示以下内容,表明它确实是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. 我已经检查了几个SO张贴关于同一问题,比如这个这个 ,并且每个建议使用我使用没有任何成功这GetStringUTFChars。 Is there anything specific to z/os going on here? 这里有z / os特有的内容吗?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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