从文件

时间:2016-11-30 15:22:16

标签: vb.net

我正在开展一个帮助我访问我网站的项目 但我坚持这一步 我只想将此文件保存为vb.net中的变量和值 我正在谈论的文件看起来像

"SIM" = "Micro-SIM"
"Weight" = "168 g (5.93 oz)"
"Announced" = "2013 =  September"
"Status" = "Available. Released 2013 =  September"
"Dimensions" = "151.2 x 79.2 x 8.3 mm (5.95 x 3.12 x 0.33 in)"
"Weight" = "168 g (5.93 oz)"

因此变量将是SIM,它的值将是Micro-SIM 我也可以在xls中制作文件 感谢

1 个答案:

答案 0 :(得分:0)

使用JSON文件 如果您创建一个代表您的数据的类

Public Class Data
    Public Property SIM As String
End Class

您将能够序列化

Dim data As New Data With { .SIM = "Micro-SIM" }
Dim stringData = JsonConvert.SerializeObject(data)
File.WriteAllText("laptop.json", stringData);

反序列化

Dim data As Data = JsonConvert.DeserializeObjec(Of Data)(File.ReadAllText("laptop.json"));

然后阅读并使用值

Dim data As Data = JsonConvert.DeserializeObjec(Of Data)(File.ReadAllText("laptop.json"))

textBoxSIM.Text = data.SIM ' Will show "Micro-SIM" in textbox

或保存值

Dim data As New Data()
data.SIM = textBoxSIM.Text
File.WriteAllText("laptop.json", JsonConvert.SerializeObject(data));