关于flutter:Dart json.encode返回带有键值且不带引号的json字符串

Dart json.encode returns json string with key values without quotes

我正在尝试将字典转换为json字符串。 但是我没有得到任何字符串的引号。 我正在使用dart 2。 这是我所拥有的

1
2
3
4
5
6
  var resBody = {};
  resBody["email"] ="[email protected]";
  resBody["password"] ="admin123";
  var user = {};
  user["user"] = resBody;
  String str = json.encode(user);

输出为:

1
{user: {email: [email protected], password: admin123}}

我希望这就像一个实际的json对象

1
{"user": {"email":"[email protected]","password: admin123"}}

如何告诉dart在其周围加上引号?
我看着这个线程,正在做对用户有效的工作
难道我做错了什么 ?


这按预期工作

1
2
3
4
5
6
7
8
9
10
11
import 'dart:convert';

void main() {
  var resBody = {};
  resBody["email"] ="[email protected]";
  resBody["password"] ="admin123";
  var user = {};
  user["user"] = resBody;
  String str = json.encode(user);
  print(str);
}

版画

1
{"user":{"email":"[email protected]","password":"admin123"}}

DartPad示例