Hello Everybody,
I am having trouble getting the JSON.decode() method working. I am
accessing it in Flex with the following code:
<mx:Script>
<![CDATA[
private function
onLanguageTranslate(event:ResultEvent):void {
try {
var tempData:String = String(event.result);
var feed:Object = JSON.decode(tempData);
trace("JSON string is " + tempData);
var arr:Array = (JSON.decode(tempData) as Array);
var dp:ArrayCollection = new ArrayCollection(arr);
Results.dataProvider = dp;
trace("JSON array is :" + arr);
}
catch(error:Error) {
Alert.show("Error on search: " + error.message);
}
}
]]>
</mx:Script>
<mx:Component id="transItemRenderer">
<mx:HBox>
<mx:Text id="transText" width="100%" height="100%"
color="#000000"
selectable="false"
text="{data.responseData.translatedText}"/>
</mx:HBox>
</mx:Component>
<mx:List id="Results" width="100%" rowHeight="130"
alternatingItemColors="[#EEEEEE, #FFFFFF]" height="100%"
color="#000000"
itemRenderer="{transItemRenderer}">
</mx:List>
However, I cannot get Flex to correctly parse the JSON code into the
array. In the line:
var arr:Array = (JSON.decode(tempData) as Array);
The array never gets populated with any of the data from the JSON
file. I can see the raw json data using the trace command but the
array is always empty;
What am I doing wrong? Can someone point me in the right direction?
Thank you,
Johnny A.