2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Flutter】Flutterの文字コード&API送受信時の文字コードの扱い

Last updated at Posted at 2022-02-16

Flutterの文字コード

FlutterのString型の文字コードはUTF-16

String class
A sequence of UTF-16 code units.

API送受信時における文字コード変換

一般的に、APIサーバーはUTF-8を使用するため、文字コードを変換する必要がある。

送信時 (UTF-16→UTF-8)

import 'dart:convert';
import 'package:http/http.dart' as http;

const request = "あいうえお";
final requestUtf8 = utf8.encode(request);
await http.post(url, body: requestUtf8);

受信時 (UTF-16←UTF-8)

import 'dart:convert';
import 'package:http/http.dart' as http;

final response = await http.get(url);
final responseUtf16 = utf8.decode(response);
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?