Adobe Flex

 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Tutorialized ForumsWeb Design & DevelopmentAdobe Flex

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Tutorialized Forums Sponsor:
  #1  
Old September 1st, 2008, 11:07 AM
stinkytofu stinkytofu is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 4 stinkytofu User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 46 m 54 sec
Reputation Power: 0
Flex and JSON.decode woes

I am having some trouble getting the JSON.decode() method working.

I currently have the following JSON file in UTF-8 format:

Code:
{"states":[{"id":140,"state":"Alabama","obama":6,"mccain":5,"ec":3},
{"id":91,"state":"Alaska","obama":4,"mccain":5,"ec":3}],
"USA":{"obama":7450, "mccain":7450}
}


I am accessing it in Flex with the following code:

Code:
<mx:Script>
private function onJSONLoad(event:ResultEvent):void
{
	var rawData:String = String(event.result);
	var countries:Array = (JSON.decode(rawData) as Array);
			
	Alert.show(countries.length as String);
	var dp:ArrayCollection = new ArrayCollection(arr);

	voteTable.dataProvider = dp;	
}
]]>
</mx:Script>

<mx:HTTPService
	id="service"
	resultFormat="text"
	fault="faultHandler(event)"
	url="http://localhost/gec/vote.json"
	result="onJSONLoad(event)" 
	showBusyCursor="true" />


However, for the life of me, I cannot get Flex to correctly parse the JSON code into an array. In the line:

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

The countries array never gets populated with any of the data from the JSON file, even though the contents of the rawData variable correctly contain all the JSON code. The countries array is always empty.

What am I doing wrong? Can someone point me in the right direction? Is there a problem with the JSON code structure? Is there something remarkably stupid I am overlooking? Hope someone can help me look at this with a fresh pair of eyes and see if they can spot the problem, because I have really hit a wall here.

Help me Obi-wan, you're our only hope!! I have been working on this problem for the past two days and really don't know where else to turn to for help!

Many thanks!

Phil

Last edited by stinkytofu : September 1st, 2008 at 12:05 PM. Reason: code correction

Reply With Quote
Reply

Viewing: Tutorialized ForumsWeb Design & DevelopmentAdobe Flex > Flex and JSON.decode woes


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap