日期:2014-05-16  浏览次数:20819 次

[高分求救啊]jni的C++实现中,调用iconv转UTF-8到GB18030老失败
在linux下转UTF-8到GB18030,结果老为空,都试了几天了,结果都不正确,谁能救救我啊,以下是我的源代码:
EncodeMessage:该参数类型为jsring,EncodeMessage= "ab你好吗 "(从java传过来的)
char   *temp;//= " ";
int   len,reqBuffLen;
size_t   length,length2=100,length3=100;
const   jchar   *jwstr;

//temp=(char*)env-> GetStringChars(EncodeMessage,0);//返回的应当是UTF-16,即Unicode
//reqBuffLen=env-> GetStringLength(EncodeMessage);
temp=(char*)env-> GetStringUTFChars(EncodeMessage,0);//返回的应当是UTF-8
reqBuffLen=env-> GetStringUTFLength(EncodeMessage);
length   =   reqBuffLen;

printf( "temp=%s\n ",temp);//正确显示
printf( "reqBuffLen=%d\n ",reqBuffLen);
char   *pmbbuf=(char*)malloc(length);
iconv_t   cd;
//             cd=iconv_open( "GB18030 ", "UTF-16 ");
cd=iconv_open( "GB18030 ", "UTF-8 ");//成功
if   (cd==0){
  printf( "iconv_open   fails\n ");
  return   -1;
}

size_t   rt;
if(rt=(int)iconv(cd,&temp,&length,&pmbbuf,&length2)==-1){//成功
printf( "iconv   failse\n ");
return   -1;
}
iconv_close(cd);
printf( "pmbbuf=%s\n ",pmbbuf);//pmbbuf结果不是空,就是乱七八糟的东西
printf( "len=%d\n ",length2);

结果不兑,那位大侠给看看啊,急死我了


------解决方案--------------------
try to set konsole encoding .

go home , byebye, ha ha