如何用数组数组解析扑扑中的json? [英] How to parse json in flutter with arrays of arrays?
本文介绍了如何用数组数组解析扑扑中的json?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用flutter解析包含数组值数组的json.我知道这种json格式无效,但是很遗憾,我需要对其进行解析.
How to parse the json which contains array of array values using flutter. I know that this json format is not a valid but unfortunately I need to parse it.
{
ModuleEId: [
[
"Test Equipment - R&D",
"GPU_0001_180 KVA Dual AC 28.5V DC"
],
[
"Test Equipment - Electronics",
"GPU_0004_180 KVA Dual AC 28.5 V DC"
]
]
}
推荐答案
要解析json,您可以使用包dart:convert
中的json.decode(jsonString)
.但是首先,您需要修复格式.
To parse a json you can use json.decode(jsonString)
from package dart:convert
. But first, you need to fix the format.
在这种情况下,您可以使用例如replaceAll
方法添加双引号.
In this case, you could use for example replaceAll
method to add the double quotes.
String jsonString = "/*loaded json*/";
jsonString = jsonString.replaceAll('ModuleEId', '"ModuleEId"');
然后
final parsed = json.decode(jsonString);
完整示例: Dartpad
这篇关于如何用数组数组解析扑扑中的json?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文