【问题标题】:json string casting issuejson字符串转换问题
【发布时间】:2019-07-25 08:34:25
【问题描述】:

数据[i]['title']= {varent_pos: 1, varent_ct: 0, title: Aashirvaad Atta with Multigrains pouch, imageslist: [], varent_id: null, id: 43469930505}

                    try {
                      final parsed = json.decode(data[i]['title']);

                    } on FormatException catch (e) {
                      print("That string didn't look like Json.");
                    } on NoSuchMethodError catch (e) {
                      print('That string was null!');
                    }"

但它显示“那个字符串看起来不像 Json”

print(data[i]['title']);

{varent_pos: 1, varent_ct: 0, title: Aashirvaad Atta with Multigrains pouch, imageslist: [], varent_id: null, id: 43469930505}

【问题讨论】:

    标签: dart flutter flutter-dependencies


    【解决方案1】:

    首先尝试打印 data[i]['title'] 的内容,以确保它是一个字符串并且看起来有效。

    之后,您可以尝试通过 https://jsonlint.com/ 该 linter 运行 JSON。

    最后但未列出尝试在 catch 语句中打印实际异常,也许它包含更多有用的信息。

    【讨论】:

    • 我明白了,实际上 data[i]['title'] 的内容不是字符串而是 Map 已经。你不必解码它,它已经被解码了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 2023-03-31
    相关资源
    最近更新 更多