# Loading JSON / formatting non-array data

**URL:** https://forum.kirupa.com/t/loading-json-formatting-non-array-data/324021
**Category:** flash
**Created:** [July 28, 2011, 8:40pm UTC](https://forum.kirupa.com/t/loading-json-formatting-non-array-data/324021 "2011-07-28T20:40:10Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![m\_elemental](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@m\_elemental](https://forum.kirupa.com/u/m_elemental)
#### Post date: [July 28, 2011, 8:40pm UTC](https://forum.kirupa.com/t/loading-json-formatting-non-array-data/324021/1 "2011-07-28T20:40:10Z")

</div>

How to format JSON data without using brackets for an array?

To start with, this works (to be followed by what doesn’t):

// +++++ json

{ “cats”:  
[

{  
“pet” : “Jazzy”,  
“about” : “Jazzy is a fast cat.”  
},

{  
“pet” : “Miss Kitty”,  
“about” : “Miss Kitty loves catnip.”  
}

]  
}

// +++++ actionScript

package {

```
import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.Event;
import com.adobe.serialization.json.JSON;

public class loadJSON extends Sprite {

    private var _textField;
    private var _textFormat;
    private var _cat;

    private var _urlRequest;
    private var _textLoader;
    
    public function loadJSON() 
    {    
        _urlRequest = new URLRequest( "jsonSample.txt" );
        _textLoader = new URLLoader();
        _textLoader.addEventListener( Event.COMPLETE, setText, false, 0, true );
        _textLoader.load( _urlRequest );
    }
     
    private function setText( event:Event ):void
    {
        _cat = new Object();
        _cat = JSON.decode( _textLoader.data );
        
        _textField = new TextField();
        _textField.text = _cat.cats[0].pet;
            
        _textFormat = new TextFormat();
        _textFormat.size = 20;
        
        _textField.setTextFormat( _textFormat );
        
        addChild( _textField );
        
    }
}

```

}

When I format the JSON data and attempt to access it like so, I get a slew of JSONParseError(s)

// +++++ json

{ “cats”:

{ “myCat”:  
{  
“pet” : “Jazzy”,  
“about” : “Jazzy is a fast cat.”  
}  
},

{ “momsCat”:  
{  
“pet” : “Miss Kitty”,  
“about” : “Miss Kitty loves catnip.”  
}  
}

}

// +++++ actionScript

```
        _textField.text = _cat.cats.myCat.pet;
```
