在解析的json的结果上放置一个链接

时间:2014-05-05 08:44:44

标签: javascript jquery html json html5

我有这个json:

[{"Nr SAT":"SAT000000002573","Data":"25\/08\/2008","Tipo Servizio":"GR","Stato":"ciao","Attributo":"APERTURA SAT SU IMEI DUPLICATO","Marca":"LG","Modello":"U830","Modello Guasto":"353142010979931"},{"Nr SAT":"SAT000000002574","Data":"25\/04\/2012","Tipo Servizio":"GR","Stato":"ahhhhhhhhhhhhh","Attributo":"APERTURA SAT SU IMEI DUPLICATO","Marca":"LG","Modello":"U830","Modello Guasto":"353142010979931"},{"Nr SAT":"SAT000000002575","Data":"15\/08\/2012","Tipo Servizio":"Vedi anche me","Stato":"ahhhhhhhhhhhhh","Attributo":"APERTURA SAT SU IMEI DUPLICATO","Marca":"LG","Modello":"U830","Modello Guasto":"353142010979931"}]

使用这段代码解析json:

<!doctype html>
<html>
<head>
    <title>Parsing</title>
    <script type="text/javascript" src="js/jquery-2.1.0.min.js"></script>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
</head>
<script>

    $.getJSON(
        'http://sath3g.altervista.org/index.php', { get_param: 'value' }, 
        function(data) {
        // 'data' is an array of objects here
        for(var i=0; i<data.length; i++) {
        //data[i] is an individual line of excel data
            $('body').append($('<p>').html('Numero SAT: '+ data[i]["Nr SAT"]));
            $('body').append($('<p>').html('Data: '+ data[i]["Data"]))

            }
        });
</script>

    <body> 
    </body>  
</html>

一旦解析了json,我想在json上获取一个链接,该链接将我带回包含json所有数据的页面。我怎么能这样做?

2 个答案:

答案 0 :(得分:0)

如果用数字表示Nr SAT,那么你可以尝试这样 -

 $('body').append(
         $('<p>').html('Numero SAT: '+ data[i]["Nr SAT"])
                 .wrap($('<a>').prop('href','http://yourDomain.com/something/'))
 );

答案 1 :(得分:0)

为什么不这样:

$('body').append('<p><a href = http://yourlink.com>'data: '+ data[i]["Data"]</a></p>')