我如何解码这个响应体?
How do I decode this response body?
我有来自 http 推送的响应正文
"{"identifier":"00000000-0000-0000-0000-00000000000"}"
我想将 000000... 部分作为字符串
这是我代码的相关部分
.
.. async {
await http
.post(Uri.encodeFull(mainURL + registrEndPoint + _stuff))
.then((res) {
if (res.statusCode == 202) {
Map _body = jsonDecode(res.body);
// I checked debugging, the respons boy is ok
String _id =_body['identifier'];
return _id;
}...
我想我在 'mapping'
中遗漏了一些东西
我怀疑这个组合 'quote-curlyBraces-quote'
击败我的 jsonDecode;
有什么建议吗?
提前致谢
通过查看 dart:convert 文档,您会看到 jsonDecode() returns
Map<String, dynamic>
,意思是直到运行时你才知道值的类型。
Map<String, dynamic> body = jsonDecode(jsonString);
print('Howdy, ${body['identifier']}!');
添加这一行我解决了问题
String _body = res.body;
如下所述,
await http
.post(Uri.encodeFull(mainURL + registrEndPoint + _qr))
.then((res) {
if (res.statusCode == 202) {
String _body = res.body; //<--- HERE!
Map _json = jsonDecode(_body);
String _id = _json['identifier'];
return _id ;
});
谢谢大家的帮助!
我有来自 http 推送的响应正文
"{"identifier":"00000000-0000-0000-0000-00000000000"}"
我想将 000000... 部分作为字符串
这是我代码的相关部分
.
.. async {
await http
.post(Uri.encodeFull(mainURL + registrEndPoint + _stuff))
.then((res) {
if (res.statusCode == 202) {
Map _body = jsonDecode(res.body);
// I checked debugging, the respons boy is ok
String _id =_body['identifier'];
return _id;
}...
我想我在 'mapping'
中遗漏了一些东西
我怀疑这个组合 'quote-curlyBraces-quote'
击败我的 jsonDecode;
有什么建议吗?
提前致谢
通过查看 dart:convert 文档,您会看到 jsonDecode() returns
Map<String, dynamic>
,意思是直到运行时你才知道值的类型。
Map<String, dynamic> body = jsonDecode(jsonString);
print('Howdy, ${body['identifier']}!');
添加这一行我解决了问题
String _body = res.body;
如下所述,
await http
.post(Uri.encodeFull(mainURL + registrEndPoint + _qr))
.then((res) {
if (res.statusCode == 202) {
String _body = res.body; //<--- HERE!
Map _json = jsonDecode(_body);
String _id = _json['identifier'];
return _id ;
});
谢谢大家的帮助!