2016-04-13 6 views
0

anglejsで次のJSONをランダム化するにはどうすればよいですか?あなたが質問をランダム化することができますので、AngularjsでJSONをランダム化する方法

{ 
    "1": { 
      "id": "1", 
      "que": "Grand Central Terminal, Park Avenue, New York is the world's", 
      "options": { 
       "A": "largest railway station", 
       "B": "highest railway station", 
       "C": "longest railway station", 
       "D": "None of the above" 
      }, 
      "ans": "A" 
     }, 
"2": { 
      "id": "2", 
      "que": "Entomology is the science that studies", 
      "options": { 
       "A": "Behavior of human beings", 
       "B": "Insects", 
       "C": "The origin and history of technical and scientific terms", 
       "D": "The formation of rocks" 
      }, 
      "ans": "B" 
     }, 
"3": { 
      "id": "3", 
      "que": "Eritrea, which became the 182nd member of the UN in 1993, is in the continent of", 
      "options": { 
       "A": "Asia", 
       "B": "Africa", 
       "C": "Europe", 
       "D": "Australia" 
      }, 
      "ans": "B" 
     } 
} 
+0

JSONを無作為化することはどういう意味ですか? –

+0

私は自分の質問をランダム化する必要があるためにクイズのアプリケーションに取り組んでいます...どうすればこれらの質問をランダム化できますか?私はすでに私のJSONを$ map – Rudrika

答えて

0

をあなたのタスクを簡単に私はあなたが使用を示唆しているようにするにはこのようなオブジェクトの配列:

var questions= 
[ 
    { 
     "id": "1", 
     "que": "Grand Central Terminal, Park Avenue, New York is the world's", 
     "options": { 
      "A": "largest railway station", 
      "B": "highest railway station", 
      "C": "longest railway station", 
      "D": "None of the above" 
     }, 
     "ans": "A" 
    }, 
    { 
     "id": "2", 
     "que": "Entomology is the science that studies", 
     "options": { 
      "A": "Behavior of human beings", 
      "B": "Insects", 
      "C": "The origin and history of technical and scientific terms", 
      "D": "The formation of rocks" 
     }, 
     "ans": "B" 
    }, 
    { 
     "id": "3", 
     "que": "Eritrea, which became the 182nd member of the UN in 1993, is in the continent of", 
     "options": { 
      "A": "Asia", 
      "B": "Africa", 
      "C": "Europe", 
      "D": "Australia" 
     }, 
     "ans": "B" 
    } 
] 

そして、t oランダムな質問を使用する:

$scope.randomQuestion = questions[Math.floor(Math.random()*questions.length)]; 
+0

を使って変換しました。問題があれば、私はあなたに更新してもらいます。 – Rudrika

関連する問題