Merge pull request #16 from Live2D/feature/fix_encode

Fix encode.
translate
Takuya Ito 2018-11-08 17:43:15 +09:00 committed by GitHub
commit 47e93ff75e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 3 deletions

View File

@ -316,11 +316,28 @@ export namespace Live2DCubismFramework
*/
public arrayBufferToString(buffer: ArrayBuffer): string
{
let encodedString: string = String.fromCharCode.apply(null, new Uint8Array(buffer));
let decodedString: string = decodeURIComponent(escape(encodedString));
return decodedString;
let uint8Array: Uint8Array = new Uint8Array(buffer);
let str: string = "";
for(let i: number = 0, len: number = uint8Array.length; i < len; ++i)
{
str += ("%" + this.pad(uint8Array[i].toString(16)));
}
str = decodeURIComponent(str);
return str;
}
/**
*
*/
private pad(n: string): string
{
return n.length < 2
? "0" + n
: n;
};
/**
* JSON
* @param buffer