Write Base64-encoded image to file

Assuming the image data is already in the format you want, you don’t need ImageIO at all – you just need to write the data to the file: // Note preferred way of declaring an array variable byte[] data = Base64.decodeBase64(crntImage); try (OutputStream stream = new FileOutputStream(“c:/decode/abc.bmp”)) { stream.write(data); } (I’m assuming you’re using Java … Read more

How to decode JSON in Flutter?

You will need to import dart:convert: import ‘dart:convert’; Inline example String rawJson = ‘{“name”:”Mary”,”age”:30}’; Map<String, dynamic> map = jsonDecode(rawJson); // import ‘dart:convert’; String name = map[‘name’]; int age = map[‘age’]; Person person = Person(name, age); Note: When I was doing this in VS Code for server side Dart I had to specify the type: Map<String, … Read more

Decode base64_encode Image from JSON in Swift

You have to cast your dictionary value from AnyObject to String. You have also to decode your string data using .IgnoreUnknownCharacters option. Try like this if let encodedImage = json[“image”] as? String, imageData = NSData(base64EncodedString: encodedImage, options: .IgnoreUnknownCharacters), image = UIImage(data: imageData) { print(image.size) } Swift 3.0.1 • Xcode 8.1 if if let encodedImage = … Read more

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-5: ordinal not in range(128) [duplicate]

Python is trying to be helpful. You cannot decode Unicode data, it is already decoded. So Python first will encode the data (using the ASCII codec) to get bytes to decode. It is this implicit encoding that fails. If you have Unicode data, it only makes sense to encode to UTF-8, not decode: >>> print … Read more

A plain JavaScript way to decode HTML entities, works on both browsers and Node

There are many similar questions and useful answers in stackoverflow but I can’t find a way works both on browsers and Node.js. So I’d like to share my opinion. For html codes like &nbsp; &lt; &gt; &#39; and even Chinese characters. I suggest to use this function. (Inspired by some other answers) function decodeEntities(encodedString) { … Read more