angular4 獲取wifi列表中文顯示亂碼問題

問題描述:
若是搜索到的wifi是中文名稱,那麼就會顯示特殊字符好比(甿ªç”Ÿè迪),亂碼的問題。編碼

這裏須要使用 escape方法對特殊字符編碼,而後使用 decodeURIComponent解碼
具體代碼以下code

建立一個管道,在須要的地方使用便可。orm

import { Pipe, PipeTransform, Injectable } from "@angular/core";
// escape在管道中須要定義一下,要否則編譯報錯。
declare function escape(s: string): string;
@Pipe({
  name: "ascPipe"
})
@Injectable()
export class AscIIToGBKPipe implements PipeTransform {
  transform(value: any) {
    console.log(value);
    if (value) {
      let str = escape(value);
      let dec = decodeURIComponent(str);
      return dec;
    } else {
      return value;
    }
  }
}
相關文章
相關標籤/搜索