How to give json data to the datagrid in flex

0 views
Skip to first unread message

sathya kanakaraj

unread,
Sep 30, 2008, 3:46:02 AM9/30/08
to chennai-fle...@googlegroups.com
Hi,
 
Please anyone say how to use json data to the datagrid
in my application i have tree and datagrid
for both controls i need to give json data
how it can be done
please help me soon
its urgent in my project
i have done with xml data but i dono how to do with json data
 
 
Thanks & Regards
sathya

Rajan M

unread,
Sep 30, 2008, 4:17:15 AM9/30/08
to chennai-fle...@googlegroups.com

RC

unread,
Sep 30, 2008, 1:32:23 PM9/30/08
to chennai-fle...@googlegroups.com
try manipulating data with array and bind that array to datagrid.

sathya kanakaraj

unread,
Oct 1, 2008, 6:11:46 AM10/1/08
to chennai-fle...@googlegroups.com
i binded the data into array i get error in that statement only.
Actually if i use json file which i got from net it is working
but for my json file it is not working
i dono where is the error in json file.
 
My json file looks like this
description.json
{
    list:{
        value:'\n- ',
        account:[
            {
                operation:'NEW ACCOUNT',
                operationstatus:[
                    {
                        type:'Opened'
                    },
                    {
                        type:'In Progress'
                    },
                    {
                        type:'To Be Submitted'
                    },
                    {
                        type:'Updated'
                    },
                    {
                        type:'Review Required'
                    },
                    {
                        type:'Completed'
                    },
                    {
                        type:'Rejected'
                    }
                ]
            },
            {
                operation:'ACCOUNT UPDATES',
                operationstatus:{
                    type:'Updated'
                }
            },
            {
                operation:'INCOMING ACCOUNT TRANSFER',
                operationstatus:[
                    {
                        type:'In Progress'
                    },
                    {
                        type:'Review Required'
                    },
                    {
                        type:'Completed'
                    },
                    {
                        type:'Rejected'
                    },
                    {
                        type:'Others'
                    }
                ]
            },
            {
                operation:'OUTGOING ACCOUNT TRANSFER',
                operationstatus:[
                    {
                        type:'In Progress'
                    },
                    {
                        type:'Review Required'
                    },
                    {
                        type:'Completed'
                    },
                    {
                        type:'Others'
                    }
                ]
            },
            {
                operation:'OTHERS'
            }
        ]
    }
}
 
And my mxml file looks like this

NewJson.mxml

<?xml version="1.0" encoding="utf-8"?>

<mx:Application

xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="add1()" width="998">

<mx:HTTPService

id="h1" url="http://twitter.com/statuses/public_timeline.json" method="POST" resultFormat="text" fault="faull(event)" result="call(event)" />

<mx:HTTPService

id="twitterService" url="http://twitter.com/statuses/public_timeline.json"

resultFormat="

text" result="onPublicTimelineResult(event)"/>

<mx:Script>

<![CDATA[

import mx.controls.Alert;

import mx.collections.XMLListCollection;

import mx.collections.ArrayCollection;

import mx.rpc.http.HTTPService;

import mx.rpc.events.ResultEvent;

import mx.rpc.events.FaultEvent;

import mx.formatters.DateFormatter;

import com.adobe.serialization.json.JSON;

[

Bindable]

private var publicTimeline:ArrayCollection;

[

Bindable]

private var treearr:ArrayCollection;

[

Bindable]

private var treearr1:XMLListCollection;

private

function call( event:ResultEvent ):void

{

var rawData:String = String( event.result );

Alert.show(

"hi");

Alert.show(rawData);

var arr:Array = JSON.decode( rawData ) as Array;

treearr =

new ArrayCollection( arr );

}

public

function faull(event:FaultEvent):void

{

Alert.show(event.message.toString());

}

public

function add1():void

{

h1.send();

}

private

function getFormattedDate( item:Object, column:DataGridColumn ):String

{

var dateFormatter:DateFormatter = new DateFormatter();

dateFormatter.formatString =

"MMMM D, YYYY, J:NN:SS";

return dateFormatter.format( item.created_at );

}

private

function getScreenName( item:Object, column:DataGridColumn ):String

{

return item.user.screen_name;

}

private

function getScreenName1( item:Object):String

{

return item.user.screen_name;

}

public

function getnode():void

{

twitterService.send();

dg1.dataProvider= publicTimeline;

}

private

function onPublicTimelineResult( event:ResultEvent ):void

{

var rawData:String = String( event.result );

var arr:Array = JSON.decode( rawData ) as Array;

publicTimeline =

new ArrayCollection( arr );

}

private

function combochange():void

{

}

]]>

</mx:Script>

<mx:Panel

width="976" height="495" layout="absolute">

<mx:HBox

x="0" y="0" width="356" height="44">

</mx:HBox>

<mx:Tree

id="t1" labelFunction="getScreenName1" dataProvider="{treearr}" x="0" y="52" width="356" height="418" itemClick="getnode()" >

</mx:Tree>

<mx:Panel

x="364" y="0" width="582" height="470" layout="absolute">

<mx:HBox

x="10" y="10" width="552" height="30">

<mx:ComboBox

height="22" width="197" change="combochange()">

<mx:String>

All Operations</mx:String>

<mx:String>

New Accounts</mx:String>

<mx:String>

Account Updates</mx:String>

<mx:String>

Incoming Account Transfers</mx:String>

</mx:ComboBox>

<mx:ComboBox

height="22" width="187">

<mx:String>

All</mx:String>

<mx:String>

To be received</mx:String>

<mx:String>

Received</mx:String>

<mx:String>

Approved</mx:String>

</mx:ComboBox>

</mx:HBox>

<mx:DataGrid

id="dg1" height="366" y="48" width="552" x="10">

<mx:columns>

<mx:DataGridColumn

width="200" headerText="Created" labelFunction="getFormattedDate" />

<mx:DataGridColumn

width="200" headerText="Screen Name" labelFunction="getScreenName" />

<mx:DataGridColumn

headerText="Tweet" dataField="text" />

</mx:columns>

</mx:DataGrid>

</mx:Panel>

</mx:Panel>

</mx:Application>

 
 
now this mxml file works correctly but if i use my json file in the httpservice tag then it shows error at runtime. It cant bind into array. please anyone knows help to solve this issue
 
Thanks in advance
 
 
Regards,
Sathya.
Reply all
Reply to author
Forward
0 new messages