MDB到JSON转换器

时间:2016-07-23 12:13:51

标签: json ms-access

我从客户端获得了Microsoft Access MDB文件。它有大约10个表,我只需要其中一个。为了进一步使用,我必须将该表转换为JSON文件。有没有办法实现这一点(免费软件或在线工具高度赞赏)?

我在OS X 10.11上并且没有选择Windows。

4 个答案:

答案 0 :(得分:3)

我知道为时已晚,但对于其他需要在线Access数据库转换器(mdb,accdb)的人来说,我已经构建了一个在线工具,可以将几乎所有版本的Access数据库转换为JSON,MySQL转储文件或SQLite。 / p>

以下是链接:https://lytrax.io/blog/tools/access-converter

我们非常感谢任何反馈,错误报告或建议。

答案 1 :(得分:3)

这是一个Microsoft Access数据库模块函数,用于导出表或查询(作为字符串传递)并在与Access数据库相同的文件夹中创建带有JSON日期时间戳的文本文件:

Function toJSON(PassTblQry)
' EXPORT JSON FILE FROM TABLE OR QUERY
Dim mydb As Database, rs As Recordset
Dim VarField(255), VarFieldType(255)
Dim fld As DAO.Field, VarDat As String
Set db = CurrentDb
fn = CurrentProject.Path & "\" & PassTblQry & " " & Format(Now(), "YYYY-MM-DD HHMM") & ".json" ' define export current folder query date/time
Open fn For Output As #1    ' output to text file
Recs = DCount("*", PassTblQry) ' record count
Set rs = db.OpenRecordset("Select * from [" & PassTblQry & "]")
Nonulls = True ' set NoNulls = true to remove all null values within output ELSE set to false
fieldcount = 0
' Save field count, fieldnames, and type into array
For Each fld In rs.Fields
    fieldcount = fieldcount + 1
    VarField(fieldcount) = fld.Name
    'Debug.Print VarField(fieldcount)
    VarFieldType(fieldcount) = "TEXT"
    Select Case fld.Type
        Case 4, 5, 6, 7 ' fieldtype 4=long, 5=Currency, 6=Single, 7-Double
            VarFieldType(fieldcount) = "NUMBER"
    End Select
Next
Set fld = Nothing
Print #1, "[" ' start JSON dataset
' build JSON dataset from table/query data passed
Do While Not rs.EOF
    Print #1, "{"  ' START JSON record
    ' build JSON record from table/query record using fieldname and type arrays
    For looper = 1 To fieldcount
        VarFT = VarFieldType(looper)
        If VarFT = "NUMBER" Then QuoteID = ""     ' No quote for numbers
        QuoteID = Chr(34) ' double quote for text
        If IsNull(rs(VarField(looper)).Value) Then  ' deal with null values
            VarDat = "Null": QuoteID = ""   ' no quote for nulls
            If Nonulls = True Then VarDat = "": QuoteID = Chr(34)                       ' null text to empty quotes
            If Nonulls = True And VarFT = "NUMBER" Then VarDat = "0": QuoteID = ""      ' null number to zero without quotes
            Else
            VarDat = Trim(rs(VarField(looper)).Value)
        End If
        VarDat = Replace(VarDat, Chr(34), "'") ' replace double quote with single quote
        VarDat = Replace(VarDat, Chr(8), "")   ' remove backspace
        VarDat = Replace(VarDat, Chr(10), "")  ' remove line feed
        VarDat = Replace(VarDat, Chr(12), "")  ' remove form feed
        VarDat = Replace(VarDat, Chr(13), "")  ' remove carriage return
        VarDat = Replace(VarDat, Chr(9), "   ")  ' replace tab with spaces
        jsonRow = Chr(34) & VarField(looper) & Chr(34) & ":" & QuoteID & VarDat & QuoteID
        If looper < fieldcount Then jsonRow = jsonRow & "," ' add comma if not last field
        Print #1, Chr(9) & jsonRow
    Next looper
    Print #1, "}";  ' END JSON record
rs.MoveNext
If Not rs.EOF Then
    Print #1, "," ' add comma if not last record
    Else
    Print #1, ""
End If
Loop
Print #1, "]"  ' close JSON dataset
Close #1

End Function

答案 2 :(得分:0)

现在很安静,但是在阅读完您的答案后,我终于使用nodeJS从访问中提取数据并将其格式化为Json,如下所示:

{export.ts}

import * as adodb  from "node-adodb";
import * as fs from "fs";

// write to a new file named 2pac.txt

const connection = adodb.open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=db.mdb;');



async function toJSON(filename:string,sql:string) {
  try {
    const data = await connection.query(sql);
    const dataString=JSON.stringify(data, null, 2);

    fs.writeFile('data/' + filename, dataString, (err) => {  
      if (err) throw err;
      console.log(filename + ' saved!');
  });
  } catch (error) {
    console.log(filename + ' error !');
    console.error(error);
  }
}

答案 3 :(得分:-1)

是的,有一个解决方案,你可以把mdb访问数据库文件带到一个有Windows的人,并在该文件上使用该程序提取或转换MS Access .mdb文件到json文件你可以在这里找到proram链接以及如何在youtube上的此剪辑中使用它

https://www.youtube.com/watch?v=6adHmSfWs-o 该程序 http://konbrand.com/DownLoads/