[英]How to JSON parsing to GoogleSignInAccount data at flutter dart
I want to get JSON data from GoogleSignInAccount. 我想从GoogleSignInAccount获取JSON数据。
_googleSignIn.onCurrentUserChanged.listen((GoogleSignInAccount account) async {
if (account != null) {
auth = Auth.fromJson(json.decode(account.toString()));
_signInView.onGoogleResponse(auth);
} else {
_signInView.onGoogleResponse(null);
}
});
but account.toString() returned the response => 但是account.toString()返回了响应=>
{
displayName: Mert TUTSAK,
email: merttutsak@gmail.com
}
I want to return the JSON object. 我想返回JSON对象。
{
"displayName": "Mert TUTSAK",
"email": "merttutsak@gmail.com"
}
How to make it? 怎么做?
What you get is just what toString()
produces on a Map
. 您得到的只是toString()
在Map
上生成的。
To get a valid JSON string, use json.Encode()
or jsonEncode
(they are equivalent) 要获取有效的JSON字符串,请使用json.Encode()
或jsonEncode
(它们等效)
import 'dart:convert';
...
var json = jsonEncode(account);
print(json);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.