我有这样的绳子,

{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};
}

Json相关问答推荐

从Razor Pages的AJAX Json呈现DataTables问题.Net GET

PowerShell女士:如何处理json对象?

将JSON数组组织到菜单中

使用 JSON 和相对日期设置日历视图中 SharePoint 列表项的背景 colored颜色 格式

PostgreSQL:删除 JSONB 数组中每个元素的特定键

(已回答)JSON 读取函数返回未定义而不是预期值 - Typescript

在Databricks中如何将JSON文件作为字典读取

是否可以在有条件的情况下将 json 对象转换为 JOLT 中的数组?

SyntaxError:Object.parse(本机)AngularJS中的意外标记o

在 C# 中解析 Json rest api 响应

如何在 MVC4 中将 Json 字符串输出为 JsonResult?

如何使用 LWP 发出 JSON POST 请求?

如何自动修复无效的 JSON 字符串?

通过 JSON 发送 HTML 代码

可以在 SharedPreferences 中保存 JSON 数组吗?

YAML 将 5e-6 加载为字符串而不是数字

运算符不存在:json = json

如何从 MVC 控制器返回 Json 对象以查看

如何从 BindingResult 获取控制器中的错误文本

是否有一个 PHP 函数只在双引号而不是单引号中添加斜杠