0

私は2つのjsonを持っています。私の仕事は、2つをjsonにマージし、jsonの時間値でソートし、jsonの値を元のままにすることです。私は多くの方法を試しましたが、できません。あなたは私を助けることができますか? ありがとうございました。

json 1

{"data":[{"messageString":"xin chao lqh 1","dateSent":"2013-06-13T02:58:37.0000000-07:00","fromUserID":"4091471","userName": "yanbi"},{"messageString":"xin chao lqh 2","dateSent":"2013-06-13T02:58:54.0000000-07:00","fromUserID":"3569333","userName":" vuquyet"},{"messageString":"xin chao lqh 2","dateSent":"2013-06-13T02:59:05.0000000-07:00","fromUserID":"3878204","userName":"duongdung "}]}

ジョンソン2

{"data":[{"messageString":"こんにちは","toUserID":"3600311","dateSent":"2013-05-06T21:04:23.0000000-07:00"},{" messageString":"yes","toUserID":"4091471","dateSent":"2013-06-15T02:16:58.0000000-07:00"},{"messageString":"xin chao duongdung13","toUserID" :"3844013","dateSent":"2013-06-10T21:54:56.0000000-07:00"},{"messageString":"xin chao duongdung13 l?n 2 ","toUserID":"3844013"," dateSent":"2013-06-10T21:55:06.0000000-07:00"},{"messageString":"xin chao duongdung13 l?n 3","toUserID":"3844013","dateSent":"2013- 06-10T21:55:19.0000000-07:00"},{"messageString":"chào yanbi","toUserID":"4091471","dateSent":"2013-06-14T23:31:38.0000000-07:00"},{"messageString":" yanbi bi?t toia ?","toUserID":"4091471","dateSent":"2013-06-14T23:32:36.0000000-07:00"},{"messageString":"vâng toi chào b?n ","toUserID":"3569333","dateSent":"2013-06-14T23:42:35.0000000-07:00"},{"messageString":"sao v?yb?n ?","toUserID": "4091471","dateSent":"2013-06-14T23:43:45.0000000-07:00"}]}{"messageString":"やんびビ?トってあ?","toUserID":"4091471","dateSent":"2013-06-14T23:32:36.0000000-07:00"},{"messageString":" vâng toi chào b?n","toUserID":"3569333","dateSent":"2013-06-14T23:42:35.0000000-07:00"},{"messageString":"sao v?yb?n ? ","toUserID":"4091471","dateSent":"2013-06-14T23:43:45.0000000-07:00"}]}{"messageString":"やんびビ?トってあ?","toUserID":"4091471","dateSent":"2013-06-14T23:32:36.0000000-07:00"},{"messageString":" vâng toi chào b?n","toUserID":"3569333","dateSent":"2013-06-14T23:42:35.0000000-07:00"},{"messageString":"sao v?yb?n ? ","toUserID":"4091471","dateSent":"2013-06-14T23:43:45.0000000-07:00"}]}messageString":"sao v?yb?n ?","toUserID":"4091471","dateSent":"2013-06-14T23:43:45.0000000-07:00"}]}messageString":"sao v?yb?n ?","toUserID":"4091471","dateSent":"2013-06-14T23:43:45.0000000-07:00"}]}

4

2 に答える 2

0

jQueryをお持ちの場合は、ここでjQuery.extend(json1, json2);詳細情報を使用できます

于 2013-06-15T10:38:10.753 に答える
0

JSON がまだ解析されていない場合は、解析する必要があります。

json1 = JSON.parse(json1_string);
json2 = JSON.parse(json2_string);

JSON を解析したら、配列を連結して並べ替えます。

array = json1.data.concat(json2.data);
array.sort(function(a, b) {
  if(a.dateSent < b.dateSent) {
    return -1;
  } 
  if(a.dateSent > b.dateSent) {
    return 1;
  } else {
    return 0;
  }
});
于 2013-06-15T10:45:07.890 に答える