Skip to content

Commit

Permalink
Fix encode.
Browse files Browse the repository at this point in the history
  • Loading branch information
cubism-dev committed Nov 8, 2018
1 parent b2b7dc3 commit 46a8e08
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions Framework/utils/cubismjson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 パース対象のデータバイト
Expand Down

0 comments on commit 46a8e08

Please sign in to comment.