如何在dart flutter中将json字符串转换为json对象?

阿什塔夫

我有这样的字符串,

{id:1, name: lorem ipsum, address: dolor set amet}

我需要将该字符串转换为json,如何在dart flutter中实现呢?非常感谢你的帮助。

forJ

您必须使用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};
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何正确将json字符串转换为对象

如何在golang中将字符串转换为json?

如何在Go中将字符串转换为JSON?

如何在golang中将动态生成的数组对象数据转换为JSON格式的字符串?

Dart对象-> JSON字符串无法转换为JSON

如何在Java或android中将URL中存在的JSON数据转换为JSON字符串?

如何在JavaScript中将字符串转换为JSON对象

如何在Bash中将字符串列表转换为JSON字符串数组?

如何在bash中将JSON子元素字符串转换为真实的JSON元素

如何在Flutter中将颜色转换为字符串?

如何在bash中将json字符串转换为单个字符数组?

如何在Angular中将字符串转换为json?

如何在Javascript中将字符串转换为对象?

如何在Flutter中将字符串转换为对象?

如何在播放json中将嵌套的Json字符串转换为Json结构

如何在dart flutter中将嵌套的json字符串转换为json对象?

如何在Unity3D中将类对象转换为JSon字符串?

如何在Android中将JSON对象转换为字符串

如何在php中将JSON对象转换为纯逗号分隔的字符串?

如何在reactjs中将字符串从json响应转换为整数

如何在 Ballerina 中将 json 转换为字符串?

如何在 JavaScript 中将字符串转换为对象?

如何在 dart:flutter 中将 Future<dynamic> 转换为字符串

如何在hive中将字符串数组转换为json字符串?

如何在flutter中将二进制字符串转换为json字符串

如何在c#中将json格式字符串转换为json

如何在 dart 中将 x-www-form-urlencoded 字符串转换为 json?

如何在飞镖颤振中将json嵌套字符串转换为json

如何在 Javacript 中将 JSON 字符串转换为数组