2012-12-25 28 views
1

這是我的JSON ..我怎麼能檢索的「定義」的值作爲迭代...多使用循環mustache.js

我怎樣才能通過它循環..我只是想知道如何遍歷這個使用mustache.js JSON ... 傢伙請幫我...

{ 
    "1": { 
    "word": "gun", 
    "pos": "verb-transitive", 
    "attrtxt": "from The American Heritage\u00ae Dictionary of the English Language, 4th Edition", 
    "1": {enter code here 
     "definition": "A weapon consisting of a metal tube from which a projectile is fired at high velocity into a relatively flat trajectory." 
    }, 
    "2": { 
     "definition": "A cannon with a long barrel and a relatively low angle of fire." 
    }, 
    "3": { 
     "definition": "A portable firearm, such as a rifle or revolver." 
    }, 
    "4": { 
     "definition": "A device resembling a firearm or cannon, as in its ability to project something, such as grease, under pressure or at great speed." 
    }, 
    "5": { 
     "definition": "A discharge of a firearm or cannon as a signal or salute." 
    }, 
    "6": { 
     "definition": "One, such as a hunter, who carries or uses a gun." 
    }, 
    "7": { 
     "definition": "A person skilled in the use of a gun." 
    }, 
    "8": { 
     "definition": "A professional killer: a hired gun. " 
    }, 
    "9": { 
     "definition": "The throttle of an engine, as of an automobile." 
    } 
    }, 
    "2": { 
    "1": { 
     "definition": "To shoot (a person): a bank robber who was gunned down by the police. " 
    }, 
    "word": "gun", 
    "pos": "verb-intransitive", 
    "attrtxt": "from The American Heritage\u00ae Dictionary of the English Language, 4th Edition", 
    "2": { 
     "definition": "To open the throttle of (an engine) so as to accelerate: gunned the engine and sped off. " 
    }, 
    "3": { 
     "definition": "Maine To hunt (game)." 
    } 
    }, 

回答

1

是否有可能重新格式化JSON?擁有一切作爲一個特定的命名元素是指使用標籤,如:

{{1.1.definition}} 

塊標籤允許您循環,但具體名稱限制的東西,如:

{{#1}}{{word}}{{/1}} 

與陣列格式化它將使遍歷更容易:

{ 
    "Words" : [{ 
      "word" : "gun", 
      "pos" : "verb-transitive", 
      "attrtxt" : "from The American Heritage\u00ae Dictionary of the English Language, 4th Edition", 
      "definitions" : [ 
       "A weapon consisting of a metal tube from which a projectile is fired at high velocity into a relatively flat trajectory.", 
       "A cannon with a long barrel and a relatively low angle of fire.", 
       "A portable firearm, such as a rifle or revolver.", 
       "A device resembling a firearm or cannon, as in its ability to project something, such as grease, under pressure or at great speed.", 
       "A discharge of a firearm or cannon as a signal or salute.", 
       "One, such as a hunter, who carries or uses a gun.", 
       "A person skilled in the use of a gun.", 
       "A professional killer: a hired gun. ", 
       "The throttle of an engine, as of an automobile." 
      ] 
     }, { 
      "word" : "gun", 
      "pos" : "verb-intransitive", 
      "attrtxt" : "from The American Heritage\u00ae Dictionary of the English Language, 4th Edition", 
      "definitions" : [ 
       "To shoot (a person): a bank robber who was gunned down by the police. ", 
       "To open the throttle of (an engine) so as to accelerate: gunned the engine and sped off. ", 
       "Maine To hunt (game)." 
      ] 
     } 
    ] 
}