/* GroupBegin General */ 
.style1 {  
padding-top:50px; 
padding-left:50px; 

/* GroupEnd */  
/* GroupBegin test11 */ 
#test { 
margin-top:50px; 
margin-left:50px;  
margin-bottom:50px; 

test1{ 
padding-top:50px; 
}
test2,test3{ 
word-spacing:normal; 
padding-top:50px; 

/* GroupEnd */ 想把这串css解析成一个json 字符串 格式如下
["General":{".style1":{"padding-top:50px;","padding-left:50px;"},},"#test ":{"margin-top:50px;","margin-left:50px; ","margin-bottom:50px; "},},"test1":{"padding-top:50px; "},},"test2":{"word-spacing:normal;  ","padding-top:50px; "},},"test3":{"word-spacing:normal;  ","padding-top:50px; "},}]
谢谢

解决方案 »

  1.   

    "General":{".style1":{"padding-top:50px;","padding-left:50px;"},},"#
    格式都错了吧
      

  2.   

    我不是帮你写了一个转换成json对象的方法了吗,自己改一下不就好了
      

  3.   

    运行起来没有效果。alert过所有变量。都没有值。没有办法下手去修改。
      

  4.   

    方便留个msn 或者 qq 吗。存在一个问题。一直想不到解决的办法。
      

  5.   

    <script type="text/javascript">
    function change(css){
    var groups = [],
    p0 = /\/\*(.+)\*\//g,
    p1 = /\/\* GroupBegin (.+) \*\//g,
    p2 = /\/\*\s+GroupEnd\s+\*\//g,
    p3 = /\/\* GroupBegin (.+) \*\/(.*)\/\*\s+GroupEnd\s+\*\//g,
    p4 = /\s*(\S+)\s*{([^}]*)}/g,
    p5 = /([^:]+)\s*:\s*([^;]+);/g;

    css.replace(/\s*(\r\n|\n)\s*/g, '').replace(p0, function(m, $1){
    return p1.test(m) || p2.test(m) ? m : '';
    }).replace('*\/\/*', '*\/\n\/*').replace(p3, function(m, $1, $2){
    var styles = [];
    $2.replace(p4, function(m, $1, $2){
    var sets = [];
    $2.replace(p5, function(m, $1, $2){
    sets.push('"' + $1 + ':' + $2 + ';"');
    });
    styles.push('"' + $1 + '":{' + sets.join(',') + '}');
    });
    groups.push('"' + $1 + '":{' + styles.join(',') + '}');
    });
    return '{' + groups.join(',') + '}';
    }
    </script>
    <textarea onchange="alert(change(this.value))" style="width:200px; height:200px;">
    /* GroupBegin General */ 
    style1 {  
    background-image:None; 
    word-spacing:normal;  
    padding-top:50px; 
    padding-left:50px;  

    /* GroupEnd */  
    /* GroupBegin test11 */ 
    test {  
    margin-top:50px; 
    margin-left:50px;  
    margin-right:50px; 
    margin-bottom:50px;  

    test1{  
    word-spacing:normal; 
    padding-top:50px;  

    /* GroupEnd */ 
    </textarea>