0

ユーザーが本を検索できるflex(flash builder 4.5)で小さなプロジェクトを作成しています。現時点では書籍を入手できますが (Google Books API を使用しています)、JSON 形式で受け取ります。

データグリッドにいくつかのフィールドを表示できるように、代わりにこれを xml で取得したいと思います。

これまでのところ、as3corelib をダウンロードしてプロジェクトにリンクしました。しかし、JSON をデコードする方法がわかりません。JSON の例

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" 
                   xmlns:mx="library://ns.adobe.com/flex/mx"
                   creationComplete="application1_creationCompleteHandler(event)"
                   >
<fx:Script>
    <![CDATA[
        import com.adobe.serialization.json.JSON;

        import mx.controls.Text;
        import mx.events.FlexEvent;
        import mx.rpc.events.ResultEvent;
        [Bindable] private var api_request:String;

        import com.adobe.serialization.json.JSONDecoder;


        protected function application1_creationCompleteHandler(event:FlexEvent):void
        {
            // TODO Auto-generated method stub
            btnSearch.addEventListener(MouseEvent.CLICK, Zoek);
        }

        protected function Zoek(event:MouseEvent):void
        {
            // TODO Auto-generated method stub
            var api_url:String='https://www.googleapis.com/books/v1/volumes?q=';
            var api_tag:String=search.text;

            api_request= api_url + api_tag

            GoogleBooks.send(); 


        }

        protected function GoogleBooks_resultHandler(event:ResultEvent):void
        {

            txtResult.text=event.result as String;
            //JSONDecoder(txtResult.text);

        }

    ]]>
</fx:Script>
<fx:Declarations>
    <s:HTTPService id="GoogleBooks" url="{api_request}" resultFormat="text" result="GoogleBooks_resultHandler(event)" />


</fx:Declarations>
<s:Button x="175" y="40" label="Button" id="btnSearch"/>
<s:TextInput x="26" y="38" id="search"/>

<s:TextArea id="txtResult" x="32" y="112" width="539" height="312"/>
</s:WindowedApplication>

私の質問は次のとおりです。JSONをデコードして、Textareaでxmlを表示するにはどうすればよいですか?

4

1 に答える 1

0

データをどのように使用するかによって異なります。あなたは単にすることができます

var data:Object = JSON.decode(jsonString);

または、JSONDecoder クラスを使用して同じことを行うことができます。

var decoder:JSONDecoder = new JSONDecoder(jsonString, jsonStringMatchesStandard);
var data:Object = decoder.getValue();

または、JSONDecoder を使用して、トークンごとに文字列をデコードできます。

var decoder:JSONDecoder = new JSONDecoder(jsonString, jsonStringMatchesStandard);
var token:JSONToken = decoder.nextToken();

ライブラリの使用方法に関する適切なガイダンスを提供するソースのコメントを確認することをお勧めします。

https://github.com/mikechambers/as3corelib/tree/master/src/com/adobe/serialization/json

于 2013-07-24T11:00:29.300 に答える