Not Getting desired json response in Dart

后端 未结 1 1916
伪装坚强ぢ
伪装坚强ぢ 2021-01-25 04:50

I am currently building an app to get a data from a json api. I want to get the number 54 from the json code.

here is the json link

I have tried making model cla

相关标签:
1条回答
  • 2021-01-25 05:12

    If you look at your json, you will see that it is entirely surrounded by [...], meaning that it is a json array. json.decode will convert this into a Dart List<Map<String, dynamic>>. It looks like you want the first / zero'th element of this array/list.

    Change:

    var line = teerModel["text"].replaceAll(new RegExp(r"(\s\n)"), "");
    

    to

    var line = teerModel[0]["text"].replaceAll(new RegExp(r"(\s\n)"), "");
    

    Don't forget to call setState so that your widget rebuilds itself.

    0 讨论(0)
提交回复
热议问题