替换json对象中的单词

Replace a word in a json object

本文关键字:单词 对象 json 替换      更新时间:2023-09-26

我正试图用以下字符串中的det替换tmb:

http://content7.flixster.com/movie/11/17/69/11176945_tmb.jpg

这是我试过的代码。

(function($) {
    $(document).ready(function() {
        var $apikey = 'myapikey',
            $apiURL = 'http://api.rottentomatoes.com/api/public/v1.0.json?apikey=',
            $topboxoffice = 'http://api.rottentomatoes.com/api/public/v1.0/lists/movies/upcoming.json?apikey=',
            $topboxofficeSearch = $topboxoffice + $apikey;
        $.ajax({
            url: $topboxofficeSearch,
            dataType: 'jsonp',
            success: function(response){

                var $movies = response.movies,
                    $moviehtml = $("#movies");

                $.each($movies, function(index, $movie){
                    var $poster = $movie.posters.original;
                    $poster.replace("tmb", "det");
                    //console.log($poster);
                    $("#movies").append( '<img src= '+$poster+ '>');
                });
            },
            error: function(){
                console.log("error");
            }
        });
    });
})(jQuery);

我尝试使用javascript.replacement(),但似乎不起作用。任何帮助都会很棒。

您需要分配te替换。Te replace()函数返回替换结果

$poster = $poster.replace("tmb", "det");