Chinaunix首页 | 论坛 | 博客
  • 博客访问: 404615
  • 博文数量: 21
  • 博客积分: 5030
  • 博客等级: 大校
  • 技术积分: 1275
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-16 09:18
文章分类
文章存档

2012年(1)

2011年(6)

2010年(2)

2009年(1)

2008年(11)

我的朋友

分类:

2011-04-13 11:53:21

sort_by

    $json = $json->sort_by($function_name)
    $json = $json->sort_by($subroutine_ref)

If $function_name or $subroutine_ref are set, its sort routine are used in encoding JSON objects.

   $js = $pc->sort_by(sub { $JSON::PP::a cmp $JSON::PP::b })->encode($obj);
   # is($js, q|{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9}|);

   $js = $pc->sort_by('own_sort')->encode($obj);
   # is($js, q|{"a":1,"b":2,"c":3,"d":4,"e":5,"f":6,"g":7,"h":8,"i":9}|);

   sub JSON::PP::own_sort { $JSON::PP::a cmp $JSON::PP::b }

As the sorting routine runs in the JSON::PP scope, the given subroutine name and the special variables $a, $b will begin 'JSON::PP::'.

阅读(986) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~