dart JSON String convert to List String

后端 未结 3 437
南旧
南旧 2021-01-04 10:08

I have an API that calls the json String array as follows:

[
  \"006.01.01\",
  \"006.01.01 1090\",
  \"006.01.01 1090 1090.950\",
  \"006.01.01 1090 1090.95         


        
3条回答
  •  轮回少年
    2021-01-04 10:34

    The result of parsing a JSON list is a List. The return type of jsonDecode is just dynamic.

    You can cast such a list to a List as

    List stringList = (jsonDecode(input) as List).cast();
    

    You can also just use it as a List and then assign each value to String:

    List rellyAStringList = jsonDecode(input);
    for (String string in reallyAStringList) { ... }
    

    The effect is approximately the same - each element is checked for being a string when it is taken out of the list.

提交回复
热议问题