jquery - 从文本文件的 Section 中生成 JSON 数据
问题描述
我正在尝试使用这种格式从文本文件中创建一个 JSON 对象:
[query]
query1 = SELECT * FROM TBL
query2 = SELECT * FROM VIEWS
[process]
process1 = exec tree
process2 = exec four
我怎样才能让它变成这样:
[
{query :{
query1 : select * from tbl,
query2 : select * from views},
{
process : {process1 : exec tree, prcoess2: exec four
}
]
jQuery代码:
$(document).ready(function() {
$.ajax({
url: "file.ini",
dataType: "text",
success: function(r) {
var $txt = r.split("\n") $.each($txt, function() {
if (this.length > 0) {
if (this.match(/[[]]/g) != null) {}
}
});
},
error: function(r) {
console.log(r.responseText);
}
});
});
解决方案
推荐阅读
- yeoman - Yeoman 发电机启动极慢
- android - PopupWindow 重叠 textView
- scala - 嵌套 WrappedArrays 上的 Spark 映射
- laravel - 我的网站不会在 laravel 的移动设备上滚动
- python - 在 Ruamel Yaml 中加载重复键
- java - 杰克逊 JSON 表示问题
- excel - 在 VBA 中,用文本值替换公式输出
- macos - 查找 Active Directory 的结构
- python - 在 def 函数中打印 txt 文件
- sql-server - What-IF 视图比较器的 UNION NULLS 后续行动