JSONobject:调用null的子方法'substr'

时间:2013-11-04 12:05:59

标签: substr jsonobject

请建议我

 var rest = JSONobject[i]["descrizione"];
 var descr = rest.substr(0,15);

错误:无法调用null

的方法'substr'

但“var rest”不为空。

代码已完成:

 $.ajax({
    type: "GET",
    url: "get_info_campotrincerato.php",
    success: function (result) {
        var JSONobject = JSON.parse(result);
        var jnCount = JSONobject.length;

        for (var i = 0; i < jnCount; i++) {

            var marker = new L.Marker(new L.LatLng(JSONobject[i]["lat"], JSONobject[i]["lng"]),{ icon: myIcon1 });
            var rest = JSONobject[i]["descrizione"];
            var descr = rest.substr(0,15);

            var list = "<dl>"
                    + "<dt><b>ID:</b> " + JSONobject[i]["id"] + "</dt>"

                    + "<dt>" + descr + "</dt>"
                    + "<a href='?id=" + JSONobject[i]["id"] + "'>...go</a>";



            marker.bindPopup(list);             
                marker.on('dblclick', function(e){
                    marker.openPopup();
                    });

0 个答案:

没有答案