본문 바로가기

Dart

Type 'String' is not a subtype of type 'int' of 'index'

보통 모델만들어서 http 통신할때 json 파싱할때 문자열에 인덱스로 접근하려고하거나 할때 생기는 오류임.

 

var a = jsondecode(res.body).cast<Map<String,dynamic>>();

print(${a[0]['Fiends'][0]['email']}');  => "soon@naver.com" 출력

그런데 a['Friends][0]['email'] => 이런식으로 하면 문자열값으로  인덱스에 엑세스 할수 없을때 발생하는 오류라고 생각하며됨.

'Dart' 카테고리의 다른 글

[Future.delay]  (0) 2020.08.13
ListView.Builder 컬럼안에서 실행할때 오류 해결하는방법  (0) 2020.05.07
Switch(조건문)사용하기  (0) 2020.05.01
for문 forEach문 사용하기  (0) 2020.05.01
.map 사용하기  (0) 2020.05.01