1

こんにちは、私はこの Web サイトの Web サービスからこの json ファイルを取得しようとしています。

ただし、この「Uncaught SyntaxError: Unexpected token」が表示されますが、何が問題なのかわかりません。

これはjsonファイルを呼び出すための私のコードです:

var pts = [];
    $.getJSON("http://172.20.192.218:8080/DC_Local/rest/datacorrelation?type=/soccer/football_team&limit=20&callback=?", function(data) {
        //JSON.parse(data);

        $.each(data, function(i,v){
            pts.push([v.topic, v.audience.length]);
        });
     });

これは私が取得しようとしている私のjsonファイルです:

{"data":[{"id":"/en/arsenal_fc","topic":"Arsenal F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/ajax_amsterdam","topic":"Ajax Amsterdam","audience":[],"type":"/soccer/football_team"},{"id":"/en/az_alkmaar","topic":"AZ Alkmaar","audience":[],"type":"/soccer/football_team"},{"id":"/en/as_roma","topic":"A.S. Roma","audience":[],"type":"/soccer/football_team"},{"id":"/en/ac_milan","topic":"A.C. Milan","audience":[],"type":"/soccer/football_team"},{"id":"/en/acf_fiorentina","topic":"ACF Fiorentina","audience":[],"type":"/soccer/football_team"},{"id":"/en/bristol_city_fc","topic":"Bristol City F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/charlton_athletic_fc","topic":"Charlton Athletic F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/ac_chievoverona","topic":"A.C. Chievo Verona","audience":[],"type":"/soccer/football_team"},{"id":"/en/chelsea_fc","topic":"Chelsea F.C.","audience":[{"information":[{"category":"Athlete","source":"Frank Lampard"}],"username":"Tan Jercia","userid":"100003921730958"},{"information":[{"category":"Athlete","source":"Didier Drogba"},{"category":"Athlete","source":"Frank Lampard"},{"category":"Professional sports team","source":"Chelsea Football Club"},{"category":"favorite_athletes","source":"Peter Cech"},{"category":"favorite_athletes","source":"Didier Drogba"},{"category":"favorite_athletes","source":"Frank Lampard"}],"username":"Ang Peterson","userid":"100003914111287"}],"type":"/soccer/football_team"},{"id":"/en/england_national_football_team","topic":"England national football team","audience":[],"type":"/soccer/football_team"},{"id":"/en/fulham_fc","topic":"Fulham F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/f_c_den_bosch","topic":"F. C. Den Bosch","audience":[],"type":"/soccer/football_team"},{"id":"/en/hellas_verona_fc","topic":"Hellas Verona F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/fc_internazionale_milano","topic":"F.C. Internazionale Milano","audience":[],"type":"/soccer/football_team"},{"id":"/en/juventus_fc","topic":"Juventus F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/liverpool_fc","topic":"Liverpool F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/luton_town_fc","topic":"Luton Town F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/manchester_united_fc","topic":"Manchester United F.C.","audience":[{"information":[{"category":"Professional sports team","source":"Manchester United"}],"username":"Tan Jercia","userid":"100003921730958"}],"type":"/soccer/football_team"},{"id":"/en/plymouth_argyle_fc","topic":"Plymouth Argyle F.C.","audience":[],"type":"/soccer/football_team"}]}
4

1 に答える 1

1

$.each(data.data, function(i,v){の代わりに書く必要があり$.each(data, function(i,v){ます。

サンプル:

<!DOCTYPE html>
<html>
    <head>
        <title>Add many Elements</title>
        <script src="jquery.js"></script>
        <script>
            $(document).ready(function() {
            var dataString = '{"data":[{"id":"/en/arsenal_fc","topic":"Arsenal F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/ajax_amsterdam","topic":"Ajax Amsterdam","audience":[],"type":"/soccer/football_team"},{"id":"/en/az_alkmaar","topic":"AZ Alkmaar","audience":[],"type":"/soccer/football_team"},{"id":"/en/as_roma","topic":"A.S. Roma","audience":[],"type":"/soccer/football_team"},{"id":"/en/ac_milan","topic":"A.C. Milan","audience":[],"type":"/soccer/football_team"},{"id":"/en/acf_fiorentina","topic":"ACF Fiorentina","audience":[],"type":"/soccer/football_team"},{"id":"/en/bristol_city_fc","topic":"Bristol City F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/charlton_athletic_fc","topic":"Charlton Athletic F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/ac_chievoverona","topic":"A.C. Chievo Verona","audience":[],"type":"/soccer/football_team"},{"id":"/en/chelsea_fc","topic":"Chelsea F.C.","audience":[{"information":[{"category":"Athlete","source":"Frank Lampard"}],"username":"Tan Jercia","userid":"100003921730958"},{"information":[{"category":"Athlete","source":"Didier Drogba"},{"category":"Athlete","source":"Frank Lampard"},{"category":"Professional sports team","source":"Chelsea Football Club"},{"category":"favorite_athletes","source":"Peter Cech"},{"category":"favorite_athletes","source":"Didier Drogba"},{"category":"favorite_athletes","source":"Frank Lampard"}],"username":"Ang Peterson","userid":"100003914111287"}],"type":"/soccer/football_team"},{"id":"/en/england_national_football_team","topic":"England national football team","audience":[],"type":"/soccer/football_team"},{"id":"/en/fulham_fc","topic":"Fulham F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/f_c_den_bosch","topic":"F. C. Den Bosch","audience":[],"type":"/soccer/football_team"},{"id":"/en/hellas_verona_fc","topic":"Hellas Verona F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/fc_internazionale_milano","topic":"F.C. Internazionale Milano","audience":[],"type":"/soccer/football_team"},{"id":"/en/juventus_fc","topic":"Juventus F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/liverpool_fc","topic":"Liverpool F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/luton_town_fc","topic":"Luton Town F.C.","audience":[],"type":"/soccer/football_team"},{"id":"/en/manchester_united_fc","topic":"Manchester United F.C.","audience":[{"information":[{"category":"Professional sports team","source":"Manchester United"}],"username":"Tan Jercia","userid":"100003921730958"}],"type":"/soccer/football_team"},{"id":"/en/plymouth_argyle_fc","topic":"Plymouth Argyle F.C.","audience":[],"type":"/soccer/football_team"}]}'
                var pts = [];
        var data = JSON.parse(dataString);

        $.each(data.data, function(index,data){
            pts.push([data.topic, data.audience.length]);
        });
            });
        </script>
    </head>
    <body>
        <div class="testDiv">
            <div class="testDivPos"></div>
        </div>
    </body>
</html>
于 2013-01-15T08:47:37.913 に答える