JSONの使い方

Google Languageを使ってみたく、ドキュメントを見ていると、asからRESTで返って来るJSONを読み取る必要があるので、初めてだったがJSONを使ってみた。

JSONを扱うには、adobeが配っているcorelibを用いる。
as3corelib – Google Code

importはこのような感じ。

import com.adobe.serialization.json.JSON;

実際の使い方としては、LoaderでRESTに問い合わせ、その返ってきたデータをJSONクラスに食べさせる。インスタンスloaderが取得したデータを読み取る場合は、こんな感じ。

var jsonObj:Object = JSON.decode( loader.data );
_translate = jsonObj["responseData"]["translatedText"];

APIからのコールバックは、

{"responseData": {
    "translatedText":"Ciao mondo"
 },
 "responseDetails": null, "responseStatus": 200}

というような内容になっているので、2行目の様なアクセスで文字列を取得できる(ここでは翻訳された文章が取得できている)。

JSONも素晴らしかったが、自動翻訳してくれるGoogle Languageも素晴らしい。

2008年 8月 5日 | Posted in Flash / ActionScript3.0
タグ: ,
  1. 2011年 12月 5日 20:41 | #1

    I’m just experiencing fortunate enough to read simple things brussels just as it is exactly what I like throughout Online To you never know how much of an fascinating certainty you can find away the next time!

コメントする

XHTML: 使用可能タグ: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>