开发者

Serialize json object with date - javascript

How to serialize json object with specific date format ?

json object

{"da开发者_如何学Pythonte": "/Date(-62135596800000)/"}

to string

{"date": "Jan 01,1"}

and i am using extjs as a core library


the following code is not finished, but it should give you what you need to achieve your goal. If not, let me know :)

function rxFn(str,m1) { 
    var d = new Date(parseInt(m1,10));
    return <whatever format you wish based on the date object>
}

function fixDateFormat(jsonObject) {
    for(var i in jsonObject) {
        switch(typeof jsonObject[i]) {
            case 'object':
                fixDateFormat(jsonObject);
                break;
            case 'string':
                jsonObject[i].replace(/Date\(([0-9]+)\)/,rxFn);
        }
    }
}

The basic idea is to loop over the json object recursivly and fix all the date serializations you find.


Thanks Martin for your answer As i am using Extjs library so i have modify the code and work perfectly

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜