我有这样的绳子,
{id:1, name: lorem ipsum, address: dolor set amet}
我需要将该字符串转换为json,我如何在dart Flatter中实现它?非常感谢你的帮助.
我有这样的绳子,
{id:1, name: lorem ipsum, address: dolor set amet}
我需要将该字符串转换为json,我如何在dart Flatter中实现它?非常感谢你的帮助.
你必须用json.decode
.它接收一个json对象,并允许您处理嵌套的键值对.我给你举个例子
import 'dart:convert';
// actual data sent is {success: true, data:{token:'token'}}
final response = await client.post(url, body: reqBody);
// Notice how you have to call body from the response if you are using http to retrieve json
final body = json.decode(response.body);
// This is how you get success value out of the actual json
if (body['success']) {
//Token is nested inside data field so it goes one deeper.
final String token = body['data']['token'];
return {"success": true, "token": token};
}