<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script>
//
    var willSort = [
    {
        'name':'a',
        'age':21,
        'height':'170',
        'date':'2014-10-12'
    },
    {
        'name':'b',
        'age':19,
        'height':'170',
        'date':'2014-10-13'
    },
    {
        'name':'c',
        'age':22,
        'height':'170',
        'date':'2014-10-14'
    },
    {
       'name':'d',
        'age':2,
        'height':'170',
        'date':'2014-10-15'
    },
    {
       'name':'e',
        'age':30,
        'height':'170',
        'date':'2014-10-16'
    }
];
    
    
//alert(willSort[0].date)

/*
    @function     JsonSort 对json排序
    @param        json     用来排序的json
    @param        key      排序的键值
*/
function JsonSort(json,key){
    //console.log(json);
    for(var j=1,jl=json.length;j < jl;j++){
        var temp = json[j],
            val  = temp[key],
            i    = j-1;
        while(i >=0 && json[i][key]>val){
            json[i+1] = json[i];
            i = i-1;   
        }
        json[i+1] = temp;

}
    //console.log(json);
    return json;
}
var json = JsonSort(willSort,'date');
//console.log(json);
          // alert(json.length)

for(var i=0;i<json.length;i++){
    alert(json[i].date)
//var date=(json[i].date)
//    function formatDate(now)   {     
//    now=now.replace(/\/Date\(/,"").replace(/000\)\//,"");
//    now= new Date(parseInt((now*1000).toLocaleString().substr(0,24)));
//    var year=now.getFullYear();     
//    var month=jia0(now.getMonth()+1);     
//    var date=jia0(now.getDate());     
//    var hour=jia0(now.getHours());     
//    var minute=jia0(now.getMinutes());     
//    var second=jia0(now.getSeconds());     
//    return year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;     
// }
//function jia0(n){
//    if(n<10)
//    n="0"+n;
//    return n;
//}
//var date="/Date(1410340800000)/";
//document.write(formatDate(date));
}

</script>
</head>

<body>
</body>
</html>

对json排序的更多相关文章

  1. json排序 摘自百度

    var sortBy = function (filed, rev, primer) {    rev = (rev) ? -1 : 1;    return function (a, b) {    ...

  2. 数组-去重、排序方法、json排序

    1.数组去重 /*方法一: 1,'1' 会被认为是相同的; 所有hash对象,如:{x;1},{y:1}会被认为是相同的 //10ms */ Array.prototype.unique=functi ...

  3. json排序 及替换在字符串中全部替换某字符串

    var roadLine = '@ViewBag.RoadLine'; var jsonRoadLine = JSON.parse(roadLine.replace(/"/g, '\&quo ...

  4. js json 排序

    /* json:需要排序的json key:排序项 */ function JsonSort(json, key) { //console.log(json); for (var j = 1, jl ...

  5. JSON排序

    //排序之前 var arrs=[{"PageID":"1"},{"PageID":"10"},{"PageI ...

  6. json 排序

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. js json排序

    var p = [             {name:"kitty", age:12},             {name:"sonny", age:9}, ...

  8. js对JSON数据排序

    一.适用于数字排序和字幕排序json 的排序方法有很多种,这是其中最简单的一种方法. 代码如下: var sortBy = function (filed, rev, primer) {    rev ...

  9. JSON自定义排序

    var json=[{ Name:'张三', Addr:'重庆', Age:'20' },{ Name:'张三3', Addr:'重庆2', Age:'25' },{ Name:'张三2', Addr ...

随机推荐

  1. 很多事情就像看A片,看的人觉得很爽,做的人未必。

    http://m.jingdianju.com/wzgs/shenghuo/201307185135.html 转载自: 从这个角度上来说,我不太赞成过于关注第一份工作的薪水,更没有必要攀比第一份工作 ...

  2. Linux下SVN客户端安装及使用

    转载自:http://www.linuxidc.com/Linux/2015-01/111748.htm 不想自己写了,这个写的挺全的,我就按这个步骤走的,呵呵 非常感谢作者 环境说明: 系统版本:C ...

  3. 快捷键的记录,Word和PPT的一些常用操作

    1)PPT背景设置:右键->背景->背景填充下的下拉箭头->填充效果->图片-  >选择图片->确定->选择应用或应用全部 2)Word,PPT求和符号怎么打 ...

  4. redis集群安装

    1.普通安装 安装环境 centos 6.8 1.安装必要包 yum install gcc yum -y install wget 2.下载解压 wget http://download.redis ...

  5. z-index和transform

    z-index和transform是CSS中的属性,但很少同学将二者联系到一起,感觉他们八杆子打不上.事实真的是这样吗?如果你也不能确认,这篇文章就值得你花点时间阅读.因为阅读完了,你会有所收获的. ...

  6. PHP从mysql获取数据的方法

    <?php require "database.php"; //读取数据库中的数据 $sql_1 = "SELECT * FROM test_table" ...

  7. cassandra的写过程

    如下: Message, get a new request,type:QUERY      //channelRead0函数 Message, get a new request,customPay ...

  8. appcan切换帐号无法提交SVN

     C:\Documents and Settings\Administrator\Application Data\Subversion\auth\svn.simple 

  9. tomcat连接池配置详解

    <bean class="org.apache.tomcat.jdbc.pool.PoolProperties"> <property name="ur ...

  10. 清空stringbuilder

    大家知道对于字符串频繁拼接是使用stringbuilder.Append方法比使用string+=方法效率高很多,但有时需要清空stringbuilder时却不知道怎么清空,因为它没有clear或em ...