Windows Dev Center

Getting "JavaScript runtime error: No mapping for the Unicode character exists in the target multi-byte code page." Error when reading certain JSON files


  • I'm getting the error:  
      JavaScript runtime error: No mapping for the Unicode character exists in the target multi-byte code page.
    When I read certain JSON files from my local directory.  I have code as follows that does work for other json files.  How can I read this file that apparently has multi-byte data in it?
        function ReadAllDataFile(fileNameInLocalTree) {
            fileNameInLocalTree = "\data\\legislators.getList.json";
            var packagex = Windows.ApplicationModel.Package.current;
            var installedLocation = packagex.installedLocation;
            //var output = ["Installed Location: " + installedLocation.path];
            installedLocation.createFileAsync(fileNameInLocalTree, Windows.Storage.CreationCollisionOption.openIfExists).then(function (dataFile) {
                dataFile.openAsync( (stream) {
                    var size = stream.size;
                    if (size == 0) {
                        // Data not found
                    else {
                        var inputStream = stream.getInputStreamAt(0);
                        var reader = new Windows.Storage.Streams.DataReader(inputStream);
                        reader.loadAsync(size).then(function () {
                            var contents = reader.readString(size);

    Peter Kellner Microsoft MVP • ASPInsider
    3 มกราคม 2555 19:28


  • The error means what it sounds like:  There is some data that cannot be represented as a string in your code page.

    You should read it as binary data and then do with it what you need to.  Of course if you need it as a string, you will not be able to use that particular file (perhaps it is corrupt).  You could either use the readBuffer or readBytes methods on the DataReader for binary data.

    This sample uses the byte method:

                                // Get the stream starting from byte 0.
                                imageStream = operation.getResultStreamAt(0);
                                // Convert the stream to MS-Stream.
                                //var msStream = msWWA.createStreamFromInputStream(contentType, imageStream);
                                var reader = new Windows.Storage.Streams.DataReader(imageStream);
                                function (readsize) {
                                    var array = new Array(readsize);
                                    //                                array = reader.readBuffer(size);





    Jeff Sanders (MSFT)
    • ทำเครื่องหมายเป็นคำตอบโดย Peter KellnerMVP 3 มกราคม 2555 21:26
    3 มกราคม 2555 19:53