admin管理员组文章数量:1289866
I just simply want something that will take a textarea full of CSS and turn it into JSON using the CSS JSON method.
{
"selector-1":{
"property-1":"value-1",
"property-n":"value-n"
}
}
.html
Does anyone know of something that will decode CSS into JSON? It would also be helpful if it could encode it as well.
I just simply want something that will take a textarea full of CSS and turn it into JSON using the CSS JSON method.
{
"selector-1":{
"property-1":"value-1",
"property-n":"value-n"
}
}
http://www.featureblend./css-json.html
Does anyone know of something that will decode CSS into JSON? It would also be helpful if it could encode it as well.
Share Improve this question edited Apr 19, 2013 at 1:23 Case asked Apr 19, 2013 at 1:15 CaseCase 4,2825 gold badges37 silver badges55 bronze badges 2- I don't know of any ready-made solution, but it wouldn't be too difficult to make something (particularly if the CSS is already parsed by the browser). – John Dvorak Commented Apr 19, 2013 at 1:17
- It's not really something I wanted to undertake. IE: dealing with background tags VS background-image I was hoping someone already solved those issues in order to save large amounts of time. – Case Commented Apr 19, 2013 at 1:19
1 Answer
Reset to default 9This js parser has both methods you are looking for.
CSS JSON parser
// To JSON
var json = CSSJSON.toJSON(cssString);
// To CSS
var css = CSSJSON.toCSS(jsonObject);
Or jQuery plugin parser.
jQuery parser
Example css:
div div:first {
font-weight: bold;
-jquery: each(function() {alert(this.tagName);})
}
div > span {
color: red;
}
JSON output sent to the callback:
{
'div div:first' : {
'font-weight' : 'bold',
'-jquery': 'each(function() {alert(this.tagName);})'
},
'div > span' : {
'color': 'red'
}
}
You can apply css string to an element like this:
var cssJSON = '{ "display": "none" }';
var obj = JSON.parse(json);
$("#element").css(obj);
本文标签: jqueryParse Text CSS into JSON with JavascriptStack Overflow
版权声明:本文标题:jquery - Parse Text CSS into JSON with Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741404773a2376877.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论