0

I need to access a database using HTTP Get and in the URL have underscores and parameters starting with $ signs:

"https://mydataservice/__query&$format=json"

I tried every thing but Flash builder keep giving me an error in the url= line

So I'm now using URLRequest instead and I have to do all the json myself. In Android I can create a class reference to the elements I want to retrieve from the json string. How do I do this in Flash Builder 4.6 mobile? The json string has 20 columns but I only need two.

Here is how far I got and my next problem is how to bind it to a list.

package dataclass
{
     [Bindable]
     public class DataTable extends Object
     {
          public function DataTable()
          {
              super();
          }

          public  var d:String;{
                public var result:Array;{

                       public var Name:String = new String();

                       public var Phone:String = new String();
                 }
          }
     }
} 



  protected function downloadFile():void {
            var request:URLRequest = new URLRequest ("https://mydataservice/__query&$format=json");
            var loader:URLLoader = new URLLoader();
            loader.dataFormat = URLLoaderDataFormat.TEXT;
            loader.load(request);
            loader.addEventListener(Event.COMPLETE, oncomplete);

        }

        protected function oncomplete(e:Event):void{ 
            var loader2:URLLoader = e.target as URLLoader; 
            try {
                if (loader2 != null){ 
                    var jsonParsed : Object = JSON.parse(loader2.data);
                    var dataTable:DataTable = new DataTable;            

                } 
                else{ 
                    trace("an error has occured!"); 
                } 
            }
            finally{

            }


        } 

Thanks, Kim

ketan
  • 19,129
  • 42
  • 60
  • 98
Kim HJ
  • 1,183
  • 2
  • 11
  • 37

1 Answers1

0

To print all the object properties:

var jsonParsed : Object = JSON.parse(loader2.data);
for (var key:String in jsonParsed) {
    trace(key + ': ' + jsonParsed[key]);
}
Alexander Farber
  • 21,519
  • 75
  • 241
  • 416
  • I know all the object properties and I can get them by typing: jsonParsed.d.result[0].Name or jsonParsed.d.result[0].Phone but my problem is how to create a class that I can load all results into (I don't know if the one I created would work or if it's correct) and then how to bind it to a Listview. – Kim HJ Jul 16 '12 at 00:42
  • For binding to a List use its dataProvider: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7fb8.html – Alexander Farber Jul 16 '12 at 12:54