首页 > 解决方案 > 从文本文件的 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);
        }
    });
});

标签: jqueryjsonfile

解决方案


推荐阅读