Javascript从txt文件数据库中获取数据

时间:2017-01-08 01:34:27

标签: javascript database text

所以,假设我有一个如下所示的txt文件:

[1] = {
Name = "Apple",
Description = {
    "A very tasty fruit,",
    "An apple a day keeps the doctor away."
},
Amount = 1,
Type = 0,
},

[2] = {
Name = "Banana",
Description = {
    "A very tasty yellow fruit,",
    "Bananananananananananananana Batman!"
},
Amount = 3,
Type = 0,
},

[3] = {
Name = "Cake",
Description = {
    "A very nice looking cake,",
    "It was all a lie."
},
Amount = 1,
Type = 1,
},

这包含具有以下格式的数据:

[ID] = { // int
Name = "Name", // string
Description = {"Description"}, // multiple-string
Amount = Amount, // int
Type = Type, // int
},

如何使用javascript搜索“ID”,它将输出所有数据,如下所示:

如果ID = 1

Item ID: 1
Name: Apple
Description:
A very tasty fruit,
An apple a day keeps the doctor away.
Amount: 1
Type: 0

对于C ++来说,它很简单,因为我可以获取txt文件的所有内容并将其转换为多维数组,但我对javascript很新,并且对它的工作原理知之甚少,请帮助并谢谢。

0 个答案:

没有答案