<table id="result_table">

    </table>
<script>
$(document).ready(function(){
$.getJSON("http://api.lucky4d.com/res", function(data) {
        var result_data ='';
        $.each(data.results, function(key, value){
            result_data += '<table><tbody><tr><td>';
                result_data += '<div class="result t_pmp"><div class="res_title" align="center">Damacai 1+3D</div>';
            result_data += '<div class="res_info">'+value.d+'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#'+value.i+'</div>';
            result_data += '<div class="res_body"><div class="res_m"><table class="res_main"><tbody><tr><th>1st</th><th>2nd</th><th>3rd</th></tr><tr><td>7917</td><td>2263</td><td>5848</td></tr></tbody></table></div>></tbody></table>';
            result_data += '<td>'+value.data.special[0]+'</td>';
            result_data += '<td>'+value.i+'</td>';
            result_data += '</td></tr>';
            result_data += '</div></div></div>';
            result_data += '</table>';
            });
    $('#result_table').append(result_data);
    });
});
</script>


昨天还好,今天value.data.special [0]出现错误。请帮我。谢谢。

以及如何显示r = magnum数据的结果?

最佳答案

格式化的JSON:

{
   "results":[
      {
         "r":"toto",
         "c":2,
         "d":"2018-07-29",
         "t":1532866860233,
         "data":{
            "special":[
               "4746",
               "0060",
               "-",
               "-",
               "3936",
               "2518",
               "9661",
               "1653",
               "2092",
               "8816",
               "-",
               "1548",
               "2804"
            ],
            "consolation":[
               "3280",
               "8953",
               "6893",
               "6576",
               "1330",
               "3158",
               "7200",
               "0349",
               "1754",
               "7764"
            ],
            "main":[
               "3013",
               "0506",
               "9152"
            ],
            "4djp_prize1":{
               "amount":"2707934.70"
            },
            "4djp_prize2":{
               "amount":"255871.78"
            }
         },
         "v":"721085d1dad81da157e80d3182b81add",
         "i":"4808/18",
         "o":201
      },
      {
         "r":"toto6d",
         "c":2,
         "d":"2018-07-29",
         "t":1532864380370,
         "data":{
            "numbers":[
               "147118"
            ]
         },
         "v":"f0957e5be17f9e4c5e251db1b2a58529",
         "i":"4808/18"
      },
      {
         "r":"cashsweep",
         "c":2,
         "d":"2018-07-29",
         "t":1532863170083,
         "data":{
            "special":[
               "7754",
               "0208",
               "0597",
               "2073",
               "3269",
               "9707",
               "2236",
               "5926",
               "2114",
               "5607"
            ],
            "main3d":[
               "190",
               "914",
               "477"
            ],
            "consolation":[
               "2608",
               "2656",
               "3203",
               "9693",
               "6267",
               "6116",
               "6517",
               "4517",
               "0590",
               "1397"
            ],
            "main":[
               "7190",
               "1914",
               "0477"
            ]
         },
         "v":"11e0d6bd8639997f9a91e0bff0666c21",
         "i":"3967/18"
      },
      {
         "r":"toto5d",
         "c":2,
         "d":"2018-07-29",
         "t":1532864551239,
         "data":{
            "numbers":[
               "36113",
               "23815",
               "38705"
            ]
         },
         "v":"63344c509e590ff5221cdb839bfc9be6",
         "i":"4808/18"
      },
      {
         "r":"san",
         "c":2,
         "d":"2018-07-29",
         "t":1532863009680,
         "data":{
            "special":[
               "-",
               "3159",
               "8780",
               "2189",
               "1285",
               "-",
               "6382",
               "6905",
               "6204",
               "1677",
               "4938",
               "3025",
               "-"
            ],
            "consolation":[
               "4477",
               "8377",
               "8869",
               "6575",
               "0826",
               "7502",
               "6404",
               "8657",
               "5291",
               "7692"
            ],
            "main":[
               "8619",
               "1377",
               "1186"
            ]
         },
         "v":"cf349e01d9c17eceff67744f49ebf780",
         "i":"101/18"
      },
      {
         "r":"sab3d",
         "c":2,
         "d":"2018-07-29",
         "t":1532862466469,
         "data":{
            "main3d":[
               "677",
               "320",
               "640"
            ]
         },
         "v":"715ae8b765ac3331cb2c2453855def31",
         "i":"2874/18"
      },
      {
         "r":"sin4d",
         "c":2,
         "d":"2018-07-29",
         "t":1532860770876,
         "data":{
            "special":[
               "8813",
               "0854",
               "3268",
               "3016",
               "2335",
               "6243",
               "9075",
               "8780",
               "8417",
               "6523"
            ],
            "consolation":[
               "8034",
               "0121",
               "9556",
               "7995",
               "0616",
               "9381",
               "1801",
               "0410",
               "3910",
               "6201"
            ],
            "main":[
               "8988",
               "5099",
               "6640"
            ]
         },
         "v":"90bbde90e9328321fc625522d3e7c8f4",
         "i":"4296"
      },
      {
         "r":"pmp",
         "c":2,
         "d":"2018-07-29",
         "t":1532864520816,
         "data":{
            "special":[
               "2864",
               "9514",
               "9639",
               "3086",
               "2898",
               "0990",
               "3185",
               "2724",
               "8131",
               "3957"
            ],
            "main3d":[
               "809",
               "497",
               "989"
            ],
            "consolation":[
               "6348",
               "3871",
               "2134",
               "5630",
               "9819",
               "0568",
               "5861",
               "6835",
               "5588",
               "8990"
            ],
            "3djp_prize":{
               "amount":"840475.40"
            },
            "main":[
               "4809",
               "3497",
               "6989"
            ],
            "4djp_prize1":{
               "amount":"7693977.10"
            },
            "4djp_prize2":{
               "amount":"284854.20"
            }
         },
         "v":"9b97f8d93ef7e37b551e52c4946d7c40",
         "i":"4755/18"
      },
      {
         "r":"sintoto",
         "c":2,
         "d":"2018-07-26",
         "t":1532603102158,
         "data":{
            "group1_prize":{
               "amount":"2506353"
            },
            "winning_shares":{
               "group7":{
                  "no":"130,197",
                  "amount":"$10"
               },
               "group4":{
                  "no":"321",
                  "amount":"$345"
               },
               "group3":{
                  "no":"113",
                  "amount":"$1,792"
               },
               "group6":{
                  "no":"7,637",
                  "amount":"$25"
               },
               "group5":{
                  "no":"7,144",
                  "amount":"$50"
               },
               "group2":{
                  "no":"5",
                  "amount":"$58,900"
               },
               "group1":{
                  "no":"-",
                  "amount":"-"
               }
            },
            "numbers":[
               "1",
               "9",
               "13",
               "17",
               "28",
               "40",
               "37"
            ]
         },
         "v":"c4daa13c83893038809f139583aabec4",
         "i":"3391",
         "o":201
      },
      {
         "r":"magnum",
         "c":2,
         "d":"2018-07-29",
         "t":1532864580728,
         "data":{
            "special":[
               "8473",
               "3239",
               "6141",
               "9331",
               "-",
               "-",
               "7075",
               "5734",
               "-",
               "1224",
               "3683",
               "2517",
               "4704"
            ],
            "consolation":[
               "6391",
               "6314",
               "8926",
               "2017",
               "8015",
               "1587",
               "3460",
               "6109",
               "6871",
               "1977"
            ],
            "4djpg_prize1":{
               "amount":"4644067.42"
            },
            "main":[
               "9236",
               "2580",
               "2278"
            ],
            "4djpg":"36807812",
            "4djpg_prize2":{
               "amount":"191543.08",
               "won":1
            },
            "4djp_prize1":{
               "amount":"5029314.12",
               "won":1
            },
            "4djp_prize2":{
               "amount":"192073.15",
               "won":2
            }
         },
         "v":"54a384f18e9f76f3179b19b1f2865582",
         "i":"043/18",
         "o":201
      },
      {
         "r":"sab",
         "c":2,
         "d":"2018-07-29",
         "t":1532863390929,
         "data":{
            "special":[
               "4537",
               "4855",
               "9979",
               "4453",
               "5546",
               "7683",
               "8302",
               "6019",
               "-",
               "-",
               "0666",
               "-",
               "1508"
            ],
            "consolation":[
               "6969",
               "8749",
               "3357",
               "6429",
               "7318",
               "6637",
               "6631",
               "2562",
               "6156",
               "5681"
            ],
            "main":[
               "8083",
               "8017",
               "0757"
            ],
            "4djp_prize1":{
               "amount":"3436958.26"
            },
            "4djp_prize2":{
               "amount":"283746.76"
            },
            "4djp":1
         },
         "v":"1116bb676c4188117ef92f5a04dd0da5",
         "i":"2874/18"
      },
      {
         "r":"totojp",
         "c":2,
         "d":"2018-07-29",
         "t":1532864112579,
         "data":{
            "star_prize1":{
               "amount":"2933043.67"
            },
            "star_prize2":{
               "amount":"236317.40"
            },
            "star":[
               "3",
               "6",
               "34",
               "38",
               "43",
               "50",
               "14"
            ],
            "power_prize":{
               "amount":"6690206.90"
            },
            "supreme":[
               "1",
               "14",
               "21",
               "34",
               "42",
               "52"
            ],
            "power":[
               "6",
               "12",
               "38",
               "44",
               "49",
               "55"
            ],
            "supreme_prize":{
               "amount":"13609676.30"
            }
         },
         "v":"02d04e7e9eaa2c227f9fc7bb9b599f4b",
         "i":"4808/18"
      },
      {
         "r":"magnumlife",
         "c":2,
         "d":"2018-07-29",
         "t":1532864580670,
         "data":{
            "numbers":[
               "03",
               "04",
               "09",
               "15",
               "19",
               "20",
               "22",
               "24",
               "12",
               "26"
            ],
            "formula":"D"
         },
         "v":"4e9165ff7b258c99901ff434876bc738",
         "i":"043/18"
      },
      {
         "r":"pmp3p3d",
         "c":2,
         "d":"2018-07-29",
         "t":1532864520816,
         "data":{
            "special":[
               "002864",
               "149514",
               "649639",
               "903086",
               "922898",
               "020990",
               "353185",
               "482724",
               "578131",
               "333957"
            ],
            "consolation":[
               "156348",
               "843871",
               "652134",
               "265630",
               "989819",
               "900568",
               "365861",
               "186835",
               "935588",
               "348990"
            ],
            "bonus":[
               "9",
               "3",
               "7"
            ],
            "prizes":[
               {
                  "amount":"2459791.60"
               },
               {
                  "amount":"2380833.30"
               },
               {
                  "amount":"1744930.50"
               }
            ],
            "main":[
               "834809",
               "583497",
               "236989"
            ]
         },
         "v":"5ab195f8687e895e9e7ae38d6b92cfd3",
         "i":"4755/18"
      },
      {
         "r":"sablotto",
         "c":2,
         "d":"2018-07-29",
         "t":1532863390333,
         "data":{
            "prize2":{
               "amount":"21223.08"
            },
            "numbers":[
               "11",
               "18",
               "19",
               "24",
               "39",
               "44",
               "37"
            ],
            "prize1":{
               "amount":"728936.58"
            }
         },
         "v":"4822821d0cf02ef3ac629ae21915c6c2",
         "i":"2874/18"
      }
   ]
}


其中第二项:

  {
     "r":"toto6d",
     "c":2,
     "d":"2018-07-29",
     "t":1532864380370,
     "data":{
        "numbers":[
           "147118"
        ]
     },
     "v":"f0957e5be17f9e4c5e251db1b2a58529",
     "i":"4808/18"
  }


没有所谓的“特殊”。就这样。

result_data += '<td>' + (value.data.special ? value.data.special[0] : '') + '</td>';


检测是否显示“特殊”或清空单元格。



对于r = magnum的数据,您只需编写if (value.r == "magnum") {...}和代码。将当前代码放入else {...}块中。

10-07 14:08