unescaped characters in json

by 9re
♥0 | Line 18 | Modified 2010-08-12 22:51:58 | MIT License
play

ActionScript3 source code

/**
 * Copyright 9re ( http://wonderfl.net/user/9re )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2aJ5
 */

package {
  import flash.display.Sprite;
  import flash.text.TextField;
  public class JSONTest extends Sprite {
    public function JSONTest() {
      import com.adobe.serialization.json.JSON;
      // 表示用TextField
      var tf:TextField = new TextField;
      addChild(tf);
      // 表示用関数
      test('"hi,\nthere!\r\tunescaped characters\"');
      // リサイズ
      tf.width = tf.textWidth + 4;
      tf.height = tf.textHeight + 4;
 
      function test(json:String, printer:Function = null):void {
        // 表示用の関数がnullならJSON.encodeで表示する
        printer ||= JSON.encode;
        // 元のJSONとstrit mode = falseでdecodeした結果を表示する
        tf.appendText(json + ' => ' + printer(JSON.decode(json)) + '\n');
      }
    }
  }
}

Forked