Question

I have a json for a spritesheet, generated by adobe flash CS6 spritesheet generator. When i try to read i get this string:"ÿþ{"

The JSON looks something like this:

 {"frames": {

    "buttons instance 10000":
    {
        "frame": {"x":0,"y":0,"w":60,"h":48},
        "rotated": false,
        "trimmed": false,
        "spriteSourceSize": {"x":0,"y":0,"w":60,"h":48},
        "sourceSize": {"w":60,"h":48}
    },
    "buttons instance 10001":
    {
        "frame": {"x":60,"y":0,"w":60,"h":48},
        "rotated": false,
        "trimmed": false,
        "spriteSourceSize": {"x":0,"y":0,"w":60,"h":48},
        "sourceSize": {"w":60,"h":48}
    },
    "buttons instance 10002":
    {
        "frame": {"x":120,"y":0,"w":60,"h":48},
        "rotated": false,
        "trimmed": false,
        "spriteSourceSize": {"x":0,"y":0,"w":60,"h":48},
        "sourceSize": {"w":60,"h":48}
    },
    "buttons instance 10003":
    {
        "frame": {"x":180,"y":0,"w":60,"h":48},
        "rotated": false,
        "trimmed": false,
        "spriteSourceSize": {"x":0,"y":0,"w":60,"h":48},
        "sourceSize": {"w":60,"h":48}
    }},
    "meta": {
    "app": "Adobe Flash CS6",
    "version": "12.0.0.481",
    "image": "panel_animations.png",
    "format": "RGBA8888",
    "size": {"w":1024,"h":2048},
    "scale": "1"
}
}

This is how i try to read the file:

protected function load(event:MouseEvent):void
{
    file = new File();
    file.addEventListener(Event.SELECT, file_select);
    file.browseForOpen("Please select a file...", [new FileFilter("JSON", "*.json")]);
}

protected function file_select(event:Event):void
{

     selectedFile = event.currentTarget as File;
    stream = new FileStream();
    //stream.open(file, FileMode.READ);
    stream.addEventListener(Event.COMPLETE, doTrace);
    stream.openAsync(selectedFile, FileMode.READ);
        }

    private function doTrace(e:Event):void 
{
    trace(stream.readUTFBytes(stream.bytesAvailable));
}

In the end the trace results in "ÿþ{", and stream.bytesAvailable=0. And if i try to parse it, of course i get Error #1132: Invalid JSON parse input.

Any help is appreciated.

moks

Was it helpful?

Solution 2

Looks like the problem is with the json file generated by flash cs6.

I created a new json file, and copy/pasted the content from the generated json file. And it worked!!

I don't know why this happened tough..

OTHER TIPS

Try using readMultiByte() instead:

private function doTrace(e:Event):void 
{
    trace(stream.readMultiByte(stream.bytesAvailable, File.systemCharset));
    stream.close();
}

Those are Byte Order bytes. ByteArray's toString function is what you should use in this case.

var obj:Object = JSON.parse(bytearray.toString());

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top