1 Reply Latest reply on Dec 27, 2007 7:12 AM by Peter Farland

    Complex JSON structure to Datagrid

    gammajack
      Hello,
      I have this app where I'm trying to parse this seemingly "complex" JSON object to an Arraycollection. The object returned from the http service request looks like this...


      {
      "COLUMNS":[
      "COUNTRY_ID","STATE_ID","COUNTRY_NAME","STATE_NAME","COUNTRY_DEFAULT_COUNTRY_ID"
      ],
      "DATA":[
      [1,1,"United States","Alabama",1],
      [1,2,"United States","Alaska",1],
      [1,3,"United States","Arizona",1],
      [1,4,"United States","Arkansas",1],
      [1,5,"United States","California",1],
      [1,6,"United States","Colorado",1],
      [1,7,"United States","Connecticut",1],
      [1,8,"United States","Delaware",1]
      ]
      }

      The simple app that I am having the trouble with looks like this...

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns="*" layout="absolute"
      creationComplete="service.send();">

      <mx:Script>
      <![CDATA[
      import mx.collections.ArrayCollection;
      import mx.rpc.events.ResultEvent;
      import com.adobe.serialization.json.JSON;
      import mx.controls.Alert;
      import mx.utils.ObjectUtil;

      private function onJSONLoad(event:ResultEvent):void{
      var rawData:String = String(event.result.data);
      var arr:Array = (JSON.decode(rawData) as Array);
      var dp:ArrayCollection = new ArrayCollection(arr.data);
      grid.dataProvider = dp;
      }
      ]]>
      </mx:Script>

      <mx:HTTPService id="service" resultFormat="text"
      url=" http://xxx.xxx.xxx.xxx/this.json"
      result="onJSONLoad(event)" />

      <mx:DataGrid id="grid" right="10" left="10" top="10" bottom="10"/>
      </mx:Application>

      Any help would be greatly appreciated.