</p>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:ns1="com.amcharts.*">

</p>

    <mx:Button x=”102” y=”276” label=”JSON Encode” click=”jsonEncode()”/> </p>

</span>

    <mx:Button x="210" y="276" label="JSON Dncode" click="jsonDecode()"/>

</p>

    </span> </p></p>

       <![CDATA[

</p>

       import com.adobe.serialization.json.JSON;

</p>

       import mx.controls.*;

</p>

   &#
160;  
private var jsonStr:String ;

</p>

      

</p>

       private function jsonEncode():void {

</p>

           var stuInfo:Object = new Object;

</p>

            stuInfo.faculty = "fa";

</p>

            stuInfo.major = "major";

</p>

            var stuStr:String = JSON.encode(stuInfo);

</p>

            jsonStr = stuStr;

</p>

            Alert.show(stuStr, "DEBUG");

</p>

       }

</p>

      

</p>

       private function jsonDecode():void {

</p>

           var jsonObject:Object = JSON.decode(jsonStr); 

</p>

        var operation:String = jsonObject.major;

</p>

        Alert.show(operation, "DEBUG");

</p>

       }

</p>

       ]]>

</p>

    </mx:Script>

</p>

</mx:Application>

</p>

转载请注明:WebLogic Android 博客 » Flex解析单个JSon对象示例代码(需要corelib)