我結束了建設自己的各種彙編...
Dim jsonArray() As String
'_______________________________________________________________
'Initializes the opening and closing braces of the JSON payload
Public Sub JSONInitialize()
ReDim jsonArray(1)
jsonArray(0) = "{"
jsonArray(1) = "}"
End Sub
'_______________________________________________________________
'Adds a string value to the JSON payload
Public Sub JSONAddString(nFieldName As String, nValue As String)
Dim temp As String
temp = jsonArray(UBound(jsonArray))
Dim index As Integer
index = UBound(jsonArray)
ReDim Preserve jsonArray(UBound(jsonArray) + 1)
jsonArray(UBound(jsonArray)) = temp
jsonArray(index) = """" & nFieldName & """:""" & nValue & ""","
End Sub
'_______________________________________________________________
'Adds an integer value to the JSON payload
Public Sub JSONAddInt(nFieldName As String, nValue As Integer)
Dim temp As String
temp = jsonArray(UBound(jsonArray))
Dim index As Integer
index = UBound(jsonArray)
ReDim Preserve jsonArray(UBound(jsonArray) + 1)
jsonArray(UBound(jsonArray)) = temp
jsonArray(index) = """" & nFieldName & """:" & nValue & ","
End Sub
所以(消毒)執行結束看起來像:
Dim o As New MyObject
Call o.JSONInitialize
Call o.JSONAddString("My JSON String Field", "Test String Value")
Call o.JSONAddInt("My JSON Int Field", 25)
o.JSONSerialize()
回報:
{"My JSON String Field":"Test String Value","My JSON Int Field": 25,}
不幸的是,它將逗號放在最後,所以它不會贏得任何選美比賽,而是我打電話給的API不在乎。
源代碼中有很多VB6類,它們在處理雙向JSON序列化方面做得很好。即使是你所聯繫的人也應該能夠,但僅僅從它的變化歷史來看,它使我脖子後面的頭髮站立起來。這可能是垃圾,因爲它依賴於總是在美國英語區域運行的程序,或者至少是靠近它的東西 - 不會告訴它有多少新的錯誤。 – Bob77