JSB StringEncoding issue when invoke js code from c

Basiclly, All Chinese characters are all in wrong state when passed into js environment. But others remain in good state like English characters.

For Example:
I pass the string “测试调用” I will get “测试调用” in js.

I invoke js like this:

JSContext *cx = ScriptingCore::getInstance()->getGlobalContext(); JSString* str = JS_NewStringCopyN(cx, value.c_str(), value.length()); jsval v = STRING_TO_JSVAL(str); jsval ret; JS_CallFunction(cx, someobj, somefunc, 1, v, &ret);

Can someone give me any advice?

This is a really big problem if you can’t read any Chinese characters into js.

After some tests, I figured out that if I pass all data with unicode format. It will work.
utf-8 is not working. It’s very sad, but at least there is a way to solve the problem.

finally, i found c_string_to_jsval can work very well.

hammer hammer wrote:

finally, i found c_string_to_jsval can work very well.

The same reason with this page: