在下面的数据示例中,我试图循环并从该participants
部分中获取所有数据。
通过 ajax 调用,我可以按如下方式访问其他数据,但我无法弄清楚该数据的 for 语句。
var userData = $.ajax({
type: "POST",
url: userurl,
dataType: "json",
//data: { point: point, claimId: id, type: val,follow: followuser }
})
.success(function(json) {
$.each(json.data, function(i,x){
var id = x.Claim.user_id; // ETC
...
这很好用。使用这种格式,我可以像这样访问个人数据:x.participants[8].user_id
. 例如,我只是不知道如何循环participants
获取所有参与者 user_id。
{
"data": [
{
"Claim": {
"img_url": null,
"id": "4",
"user_id": "3",
"claim_status": "started",
"exp": "Sep 30, 2013"
},
"User": {
"score": "0",
"id": "3"
},
"ClaimResponse": [
{
"id": "32",
"claim_id": "4",
"user_id": "14",
"created": "2013-06-10 03:18:35",
"modified": "2013-06-10 03:18:35"
},
{
"id": "107",
"claim_id": "4",
"user_id": "8",
"created": "2013-06-28 02:37:10",
"modified": "2013-06-28 02:37:10"
},
{
"id": "140",
"claim_id": "4",
"user_id": "976",
"created": "2013-06-28 04:19:22",
"modified": "2013-06-28 04:19:22"
},
{
"id": "152",
"claim_id": "4",
"user_id": "19",
"created": "2013-07-03 02:27:12",
"modified": "2013-07-03 02:27:12"
},
{
"id": "154",
"claim_id": "4",
"user_id": "1158",
"created": "2013-07-05 03:16:48",
"modified": "2013-07-05 03:16:48"
}
],
"participants": {
"14": {
"user_id": "14",
"twitter_image_url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_1_normal.png"
},
"8": {
"user_id": "8",
"twitter_image_url": "https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_3_normal.png"
},
"19": {
"user_id": "19",
"twitter_image_url": "https://si0.twimg.com/sticky/default_profile_images/default_profile_2_normal.png"
},
"1158": {
"user_id": "1158",
"twitter_image_url": "https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_5_normal.png"
}
},
"viewer": {
"isResponsed": false,
"isOwner": false,
"lockedInPoint": 0,
"response": null,
"cut_loss": false,
"cut_loss_price": null
}
},
{
"Claim": {
"img_url": null,
"id": "133",
"user_id": "14",
"claim_status": "started",
"exp": "Jul 15, 2013"
},
"User": {
"score": "-40",
"id": "14"
},
"ClaimResponse": [
{
"id": "172",
"claim_id": "133",
"user_id": "8",
"created": "2013-07-12 20:36:16",
"modified": "2013-07-12 20:36:16"
},
{
"id": "176",
"claim_id": "133",
"user_id": "1159",
"created": "2013-07-13 02:52:31",
"modified": "2013-07-13 02:52:31"
}
],
"participants": {
"8": {
"user_id": "8",
"twitter_image_url": "https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_5_normal.png"
},
"1159": {
"user_id": "1159",
"twitter_image_url": "https://twimg0-a.akamaihd.net/sticky/default_profile_images/default_profile_5_normal.png"
}
},
"viewer": {
"isResponsed": false,
"isOwner": false,
"lockedInPoint": 0,
"response": null,
"cut_loss": false,
"cut_loss_price": null
}
}
],
"errors": [],
"success": true,
"code": 200
}
编辑: 小提琴,感谢@ohgodwhy 的帮助。也许这更好地说明了我正在尝试做的事情。我想要与他们各自的声明相关的参与者图标。它很接近,但似乎从第一个索赔中吸引了所有参与者......: