Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过jQuery将json数据应用于格式化样式_Javascript_Jquery_Json - Fatal编程技术网

Javascript 通过jQuery将json数据应用于格式化样式

Javascript 通过jQuery将json数据应用于格式化样式,javascript,jquery,json,Javascript,Jquery,Json,我对以下几点有一个奇怪的问题: function loadTextbox(jsonUrl,divId){ $.getJSON(jsonUrl, function(json) { $('#' + divId).html('<h2>'+json.heading+'</h2>'); alert(json.config.headingConfig); $('#' + divId).children().css(json.co

我对以下几点有一个奇怪的问题:

function loadTextbox(jsonUrl,divId){
    $.getJSON(jsonUrl, function(json) {
        $('#' + divId).html('<h2>'+json.heading+'</h2>');
        alert(json.config.headingConfig);
        $('#' + divId).children().css(json.config.headingConfig);
    })
}
函数加载文本框(jsonUrl,divId){
$.getJSON(jsonUrl,函数(json){
$('#'+divId).html(''+json.heading+'');
警报(json.config.headingConfig);
$('#'+divId).children().css(json.config.headingConfig);
})
}
上面的警报返回:{color:'white',fontfamine:'Arial,Times,serif'}但是,文本的格式没有更改

现在有一个奇怪的部分:如果我这样做:

function loadTextbox(jsonUrl,divId){
        $.getJSON(jsonUrl, function(json) {
            $('#' + divId).html('<h2>'+json.heading+'</h2>');
            alert(json.config.headingConfig);
            $('#' + divId).children().css({color: 'white', fontFamily:'Arial, Times, serif'});
        })
    }
函数加载文本框(jsonUrl,divId){
$.getJSON(jsonUrl,函数(json){
$('#'+divId).html(''+json.heading+'');
警报(json.config.headingConfig);
$('#'+divId).children().css({color:'white',fontfamine:'Arial,Times,serif'});
})
}

它很好用。。。文本格式为Arial字体和白色。我很困惑。。。这可能意味着有一个非常简单的答案,有什么想法吗?

看起来您的
json.config.headingConfig
包含一个json字符串


您需要通过如下方式调用
$.parseJSON

将其转换为实际对象:$('#'+divId).children().css($.parseJSON(json.config.headingConfig));当我这样做时,它会给我以下错误:未捕获无效的JSON:{color:'white',fontfamine:'Arial,Times,serif'}@Yotta:您可以将其更改为有效的JSON(使用
无处不在),或者调用
eval