actionScript 解析json开源包,比官方的好

   前段时间参与了一个移动的孵化器项目,用flex来解析json,本来想用官方的as3corelib来解析json文件,不过我发现他生成的json没有格式化,生成的一堆字符串混在一起,看这不舒服,我想其他人用这个包的时候也会和我有同样的感觉,我的想法是正确的,确实有人重写了官方的json包(adobe开源的东东就是不怎么样),试了一下,解析后,果然很有条理。。。

{
    "id":"1010",
    "name":"公共素材库",
    "subclassifications":[
        {
            "id":"1011",
            "name":"悬疑"
        },
        {
            "id":"1012",
            "name":"搞笑"
        },
        {
            "id":"1013",
            "name":"生活"
        }
    ]
}

  该包的JSON.as中的方法:

 

/**
   * Encodes a object into a JSON string.
   *
   * @param o The object to create a JSON string for
   * @return the JSON string representing o
   * @langversion ActionScript 3.0
   * @playerversion Flash 9.0
   * @tiptext
   */
  public static function encode( o:Object, pretty:Boolean=false, maxLength:int=60 ):String
  { 
   return new JSONEncoder( o, pretty, maxLength ).getString();
  }
/**
   * Decodes a JSON string into a native object.
   * 
   * @param s The JSON string representing the object
   * @param strict Flag indicating if the decoder should strictly adhere
   *   to the JSON standard or not.  The default of <code>true</code>
   *   throws errors if the format does not match the JSON syntax exactly.
   *   Pass <code>false</code> to allow for non-properly-formatted JSON
   *   strings to be decoded with more leniancy.
   * @return A native object as specified by s
   * @throw JSONParseError
   * @langversion ActionScript 3.0
   * @playerversion Flash 9.0
   * @tiptext
   */
  public static function decode( s:String, strict:Boolean = true ):*
  { 
   return new JSONDecoder( s, strict ).getValue(); 
  }

 官方的我就不贴上来了,有兴趣的童鞋可以自己去官网看。。。。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值