코드
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
final myTranformer = Xml2Json();
var xmlString = '''<?xml version="1.0"?>
<site>
<tut>
<id>tut_01</id>
<author>bezKoder</author>
<title>Programming Tut#1</title>
<publish_date>2020-8-21</publish_date>
<description>Tut#1 Description</description>
</tut>
<tut∑>
<id>tut_02</id>
<author>zKoder</author>
<title>Software Dev Tut#2</title>
<publish_date>2020-12-18</publish_date>
<description>Tut#2 Description</description>
</tut>
</site>''';
myTranformer.parse(xmlString);
var jsonString = myTranformer.toParker();
final parsed = jsonDecode(jsonString)['site']['tut']
.cast<Map<String, dynamic>>();
return parsed
.map<Transaction>((json) => Transaction.fromJson(json))
.toList();
요청을 받은 결과에서 .parse
에서 에러가 나는 경우 아래와 같이 utf8.decode
를 해주면 된다.
1
2
final utf16Body = utf8.decode(response.bodyBytes);
myTranformer.parse(utf16Body);