全局变量
以下内容为程序代码:
1 ConvertHelper
2
3 Public Class ConvertHelper
4
5 '把对象序列化为Json字符串
6 Public Shared Function ToJson(ByVal fromObject As Object) As String
7 Return Newtonsoft.Json.JsonConvert.SerializeObject(fromObject)
8 End Function
9
10 ' 把Json字符串反序列化为指定类型的对象
11 Public Shared Function FromJson(Of T)(ByVal jsonString As String) As T
12 Return Newtonsoft.Json.JsonConvert.DeserializeObject(Of T)(jsonString)
13 End Function
14
15 '字符串转换成字节数组
16 Public Shared Function EncodingToBytes(ByVal s As String, Optional encode As System.Text.Encoding = Nothing) As Byte()
17 Dim encoding As System.Text.Encoding = IIf(encode Is Nothing, System.Text.Encoding.Unicode, encode)
18 Return encoding.GetBytes(s)
19 End Function
20
21 ' 字节数组转换成字符串
22 Public Shared Function EncodingToString(ByVal bytes As Byte(), Optional encode As System.Text.Encoding = Nothing) As String
23 Dim encoding As System.Text.Encoding = IIf(encode Is Nothing, System.Text.Encoding.Unicode, encode)
24 Return encoding.GetString(bytes)
25 End Function
26
27 '把DataRow值赋值到对象的实体对象
28 Public Shared Sub FromDataRow(ByVal Row As DataRow, ByRef entity As EntityBase)
29 Dim fs As System.Reflection.PropertyInfo() = entity.Gettype.GetProperties
30 Dim f As System.Reflection.PropertyInfo
31 For Each f In fs
32 If ((Not Row.DataTable Is Nothing) AndAlso Row.DataTable.DataCols.Contains(f.Name)) Then
33 Dim o As Object = Row.Item(f.Name)
34 If (Not o Is DBNull.Value) Then
35 f.SetValue(entity, o, Nothing)
36 End If
37 End If
38 Next
39 End Sub
40
41 ' 把实体值赋值到DataRow
42 Public Sub ToDataRow(ByVal entity As EntityBase, ByRef Row As DataRow)
43 Dim fs As System.Reflection.PropertyInfo() = entity.Gettype.GetProperties
44 Dim f As System.Reflection.PropertyInfo
45 For Each f In fs
46 If ((Not Row.DataTable Is Nothing) AndAlso Row.DataTable.DataCols.Contains(f.Name)) Then
47 Dim o As Object = f.GetValue(entity, Nothing)
48 If (o Is Nothing) Then
49 Row.Item(f.Name) = DBNull.Value
50 Else
51 Row.Item(f.Name) = o
52 End If
53 End If
54 Next
55 End Sub
56 End Class
57
临时表
DataTables("JSON临时表").Fill("Sele ct TOP 1 车辆照片 As imgList,车辆类型 As modelName,年检有效期 As checktime,[_Identify] From {车辆信息} Order by [_Identify] Desc","data",True)
JSON后多出来的四列:
"_Locked":null,"System_Sort_Temporary":null,"System_Filter_Temporary":null,"System_Filter_Unique":null
请教如何在JSON时屏蔽无关字段?