Unable to return to Chinese problem resolution in Android technology 13:NDK

Source: Internet
Author: User

1 questions

In order to enhance the security of the software, the HTTP request is encapsulated in JNI, that is, the HTTP request is implemented through the C language, and the string is returned. However, strings often contain Chinese, and when the return type is jstring, the JNI warning:illegal continuation byte 0xd0 error occurs because the C file in Jni has Chinese and Chinese cannot be recognized. Unable to use (*env)->newstringutf (env,s); return string.

2. The programme

2.1 The native method returns a type of byte array such as: Private native byte[] GetData ();

2.2 Implement HTTP request, data is saved in char*p;

2.3 New byte array Jbytearray array= (*env)->newbytearray (env, Len);

2.4 (*env)->setbytearrayregion (env,array,0,len,p), and finally returns an array

2.5 Convert bytes to strings in Java code, note encoding type byte[] S=getdata (); String Str=new string (S, "GB2312");

Next, you can return the Chinese data and then parse the data further.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.