I have read a file and got myself a list of integers. For most of my work this is what I want to get, but in one case I also need to convert some of List<int>
into a String
.
To be more specified, I want to encode the string in UTF-8.
This is what I just tried:
var decoder = new Utf8Decoder(figures);
print(decoder.decodeRest());
But all I get is a list of integers.
Create a list named colors . List<String> colors = ['Blue', 'Red', 'Black', 'Yellow', 'White', 'Pink']; Then, convert the List colors to a JSON string using the dart:convert library's built-in jsonEncode() function. String jsonColors = jsonEncode(colors);
Use the toString() method to convert an int or double to a string. To specify the number of digits to the right of the decimal, use toStringAsFixed(). To specify the number of significant digits in the string, use toStringAsPrecision(): // Convert an int to a string.
We have 3 steps to convert an Object/List to JSON string: create the class. create toJson() method which returns a JSON object that has key/value pairs corresponding to all fields of the class. get JSON string from JSON object/List using jsonEncode() function.
String.fromCharCodes(List<int> charCodes)
is probably what you're looking for.
List<int> charCodes = const [97, 98, 99, 100];
print(new String.fromCharCodes(charCodes));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With