0

1 つのリクエストを作成したいが、レスポンスの複数のグループを返したい場合、それらを jQuery で解析して.length各グループの情報を取得できるようにするにはどうすればよいでしょうか?

第1グループ (A)

[
   {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
   ,{"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
]

第二グループ(B)

[
   {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
   ,{"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
]

トータル レスポンス (1 回のリクエスト):

[
   {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
   ,{"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
]
,[
   {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
   ,{"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
]

または、これを適切に行うために別の方法で返却しますか? または、それらを別々に行う必要がありますか?

4

1 に答える 1

0

それらを配列、または各グループを配列またはオブジェクトの要素として持つオブジェクトにすることができます

物体

{
  "groupa":[
   {"name":"Tu\u011Frul","surname":"Topuz SR","message":"Hello World"},
   {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
    ],
  "groupb":[
    {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"},
    {"name":"Tu\u011Frul","surname":"Topuz JR","message":"Hello World"}
]}

success(data){
    data["groupa"].length//number of items in group a
    data["groupa"][0]["surname"] == "Topuz SR"//true;
    data["groupb"][1]["surname"] == "Topuz JR"//true;
}

配列

[[
   {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"},
   {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
    ],
  [
    {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"},
    {"name":"Tu\u011Frul","surname":"Topuz","message":"Hello World"}
]]


success(data){
    data[0].length//number of items in first group
}
于 2012-06-29T08:00:01.053 に答える