0

各「回答」セクションの回答数をカウントするにはどうすればよいですか?

 var json = {
  "Answers": [
    {
      "Responses": [
        {
          "ResponseID": 5,
          "RespondingUser": null,
          "ResponseDate": "\/Date(1351700419747)\/"
        },
        {
          "ResponseID": 6,
          "RespondingUser": null,
          "ResponseDate": "\/Date(1351700437387)\/"
        },
        {
          "ResponseID": 7,
          "RespondingUser": null,
          "ResponseDate": "\/Date(1351700448550)\/"
        }
      ],
      "AnswerID": 3,
      "AnswerText": "No"
    },
    {
      "Responses": [
        {
          "ResponseID": 9,
          "RespondingUser": null,
          "ResponseDate": "\/Date(1351700419747)\/"
        },
        {
          "ResponseID": 6,
          "RespondingUser": null,
          "ResponseDate": "\/Date(1351700437387)\/"
        },
        {
          "ResponseID": 7,
          "RespondingUser": null,
          "ResponseDate": "\/Date(1351700448550)\/"
        }
      ],
      "AnswerID": 4,
      "AnswerText": "Probably not"
    },
    {
      "Responses": [
        {
          "ResponseID": 50,
          "RespondingUser": null,
          "ResponseDate": "\/Date(1351700419747)\/"
        },
        {
          "ResponseID": 6,
          "RespondingUser": null,
          "ResponseDate": "\/Date(1351700437387)\/"
        },
        {
          "ResponseID": 7,
          "RespondingUser": null,
          "ResponseDate": "\/Date(1351700448550)\/"
        }
      ],
      "AnswerID": 5,
      "AnswerText": "Definitely not"
    }
  ],
  "QuestionID": 2,
  "QuestionText": "Steve Lamaq?",
  "ClosingDate": "\/Date(1351958948793)\/",
  "AskingUser": null
};

どんなアドバイスも素晴らしいでしょう!どうもありがとう

4

1 に答える 1

1
var i = json.Answers.length,
    total = 0;

while(i--){
 total += json.Answers[i].Responses.length;
}

于 2012-10-31T18:01:14.760 に答える