[Gambas-user] Error in JSON decode with large json data
Martín
mbelmonte at belmotek.net
Fri Apr 28 10:51:15 CEST 2023
This code solve the problem.
Public Sub FileBox1_Change()
Dim sContent As String
Dim vData As Variant
Dim v As Variant
Dim aContent As String[]
Dim i As Integer
Dim sOld As String
Dim sRep As String
Dim sKey As String
If Exist(FileBox1.Value) Then
If Stat(FileBox1.Value).Type = gb.File Then
If Lower(File.Ext(FileBox1.Value)) = "json" Then
sContent = File.Load(FileBox1.Value)
aContent = Split(sContent, "\n")
For i = 0 To aContent.Max
sOld = aContent[i]
If InStr(sOld, "ICD\": ") > 0 Then
If Right(sOld, 2) <> "\"," Then
sKey = Split(Split(Replace(aContent[i - 1], " \"", ""),
":")[1], " ")[0]
aContent[i] = " \"ICD\": \"" & sKey & "\","
Endif
Else
If InStr(sOld, ", ") > 0 And Right(sOld) = "," Then
sRep = Replace(sOld, ", ", "; ")
aContent[i] = sRep
Endif
Endif
Next
File.Save("/tmp/clean.json", aContent.Join("\n"))
vData = JSON.FromString(aContent.Join("\n"))
Endif
Endif
Endif
End
Regards.
Martin.
More information about the User
mailing list