$ .each data()在firefox和chrome上返回不同的结果

时间:2013-05-30 01:55:36

标签: javascript jquery json

我有一个由

发送的这种json
{
   "media":{
      "1369725029":{
         "id_profil":"5738",
         "photo_profil":"http:\/\/www.mupiz.com\/5738\/picture",
         "phrase_feed":"a ajout\u00e9 une nouvelle chanson",
         "nom_media":"La Douleur (chanson sur mon tableau)",
         "nom_profil":"KRISS",
         "url_profil":"kriss",
         "streaming":"\r\n  <div class=\"playerMedia\" onclick=\"InlinePlayer(this)\" data-url=\"http:\/\/www.mupiz.com\/mp3\/5738\/mp3_51550.mp3\" data-id=\"mp3_51550.mp3\">La Douleur (chanson sur mon tableau)<\/div>\r\n",
         "url_media":"http:\/\/www.mupiz.com\/kriss\/la-douleur-chanson-sur-mon-tab"
      },
      "1369723360":{
         "id_profil":"5738",
         "photo_profil":"http:\/\/www.mupiz.com\/5738\/picture",
         "phrase_feed":"a ajout\u00e9 une nouvelle chanson",
         "nom_media":"On the Hi-Way (chanson)",
         "nom_profil":"KRISS",
         "url_profil":"kriss",
         "streaming":"\r\n  <div class=\"playerMedia\" onclick=\"InlinePlayer(this)\" data-url=\"http:\/\/www.mupiz.com\/mp3\/5738\/mp3_54344.mp3\" data-id=\"mp3_54344.mp3\">On the Hi-Way (chanson)<\/div>\r\n",
         "url_media":"http:\/\/www.mupiz.com\/kriss\/on-the-hi-way-chanson1"
      },
      "1368389617":{
         "id_profil":"32236",
         "photo_profil":"http:\/\/www.mupiz.com\/32236\/picture",
         "phrase_feed":"a ajout\u00e9 une nouvelle vid\u00e9o",
         "nom_media":"P!nk - Just Give Me A Reason ft Nate Ruess (Real Chanty Cover) ",
         "nom_profil":"Real Chanty",
         "url_profil":"RealChanty",
         "streaming":"<iframe width=\"270px\" height=\"200px\" src=\"http:\/\/www.youtube.com\/embed\/xiDzmc59fjg\" frameborder=\"0\" allowfullscreen><\/iframe>",
         "url_media":"http:\/\/www.mupiz.com\/RealChanty\/video\/p-nk-just-give-me-a-reason-ft-nate-ruess-real-chanty-cover"
      },
      "1368384065":{
         "id_profil":"1388",
         "photo_profil":"http:\/\/www.mupiz.com\/1388\/picture",
         "phrase_feed":"a ajout\u00e9 une nouvelle chanson",
         "nom_media":"On the Hi-Way (chanson)",
         "nom_profil":"Fred.Baz1-Compositeur-Bassiste-Guitariste",
         "url_profil":"fred-bazin",
         "streaming":"\r\n  <div class=\"playerMedia\" onclick=\"InlinePlayer(this)\" data-url=\"http:\/\/www.mupiz.com\/mp3\/1388\/mp3_49786.mp3\" data-id=\"mp3_49786.mp3\">On the Hi-Way (chanson)<\/div>\r\n",
         "url_media":"http:\/\/www.mupiz.com\/fred-bazin\/on-the-hi-way-chanson"
      }
   }
}

Chrome获得“正确”命令FF没有,

有什么想法吗?

2 个答案:

答案 0 :(得分:4)

我认为您不能依赖JSON对象中的属性排序 - JSON可以按任何顺序返回。

来自http://www.json.org/

的JSON规范
An object is an unordered set of name/value pairs

可能重复吗? JSON order mixed up

答案 1 :(得分:1)

不,因为JS不维护订单,所以不需要对属性进行订购。一般的想法是因为这些是关键值对,所以不需要保持顺序。另一方面,对象数组可以并且将维护顺序,因为它由索引绑定并且是可迭代的。这就是对象数组的样子:

[
     { "name" : "test", "age" : 10 }, //index 0
     { "name" : "test1" ,"age": 15 } //index 1

 ]