Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference and preferred way between jsonEncode() and json.encode() in Dart?

In Flutter doc, it uses jsonEncode(), while in Angular doc, it uses json.encode(). What is the difference and preferred way between the two?

like image 225
sgon00 Avatar asked Dec 13 '22 12:12

sgon00


1 Answers

jsonEncode as alias for json was introduced because json often collided with a varible name json many used for the variable that holds the JSON value.

var json = http.get(...);
var data = json.decode(json); // error
var data = jsonDecode(json); // ok
like image 110
Günter Zöchbauer Avatar answered May 01 '23 06:05

Günter Zöchbauer