save working?
This commit is contained in:
parent
edbfb61166
commit
5890221678
3 changed files with 36 additions and 10 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
# windsurf rules
|
||||
.windsurfrules
|
BIN
json.db
BIN
json.db
Binary file not shown.
44
jsonlib.pb
44
jsonlib.pb
|
@ -1,4 +1,4 @@
|
|||
UseSQLiteDatabase()
|
||||
UseSQLiteDatabase()
|
||||
|
||||
Procedure InsertIntoDatabase(key$, parentKey$, type$, value$)
|
||||
query$ = "INSERT INTO json_data (key, parent_key, type, value) VALUES ('" + key$ + "', '" + parentKey$ + "', '" + type$ + "', '" + value$ + "')"
|
||||
|
@ -56,13 +56,37 @@ EndProcedure
|
|||
|
||||
; Nested array handling
|
||||
Procedure HandleNestedArray(JSONValue, parentKey$)
|
||||
Dim arrayitems(0)
|
||||
Debug "Array" + ExtractJSONArray(JSONValue, arrayitems())
|
||||
|
||||
For i = 0 To ArraySize(arrayitems())
|
||||
Debug "Array item" + arrayitems(i)
|
||||
InsertIntoDatabase(key$,parentKey$,"array",Str(arrayitems(i)))
|
||||
Next i
|
||||
arraySize = JSONArraySize(JSONValue)
|
||||
|
||||
For arrayIndex = 0 To arraySize - 1
|
||||
elementValue = GetJSONElement(JSONValue, arrayIndex)
|
||||
arrayItemKey$ = parentKey$ + "[" + Str(arrayIndex) + "]"
|
||||
|
||||
Select JSONType(elementValue)
|
||||
Case #PB_JSON_String
|
||||
value$ = GetJSONString(elementValue)
|
||||
InsertIntoDatabase(arrayItemKey$, parentKey$, "String", value$)
|
||||
|
||||
Case #PB_JSON_Number
|
||||
value$ = StrD(GetJSONDouble(elementValue))
|
||||
InsertIntoDatabase(arrayItemKey$, parentKey$, "Number", value$)
|
||||
|
||||
Case #PB_JSON_Boolean
|
||||
value$ = Str(GetJSONBoolean(elementValue))
|
||||
InsertIntoDatabase(arrayItemKey$, parentKey$, "Boolean", value$)
|
||||
|
||||
Case #PB_JSON_Object
|
||||
InsertIntoDatabase(arrayItemKey$, parentKey$, "Object", "(nested object)")
|
||||
HandleNestedObject(elementValue, arrayItemKey$)
|
||||
|
||||
Case #PB_JSON_Array
|
||||
InsertIntoDatabase(arrayItemKey$, parentKey$, "Array", "(nested array)")
|
||||
HandleNestedArray(elementValue, arrayItemKey$)
|
||||
|
||||
Default
|
||||
InsertIntoDatabase(arrayItemKey$, parentKey$, "Unknown", "(unknown type)")
|
||||
EndSelect
|
||||
Next
|
||||
EndProcedure
|
||||
|
||||
; worry about the database init later
|
||||
|
@ -127,8 +151,8 @@ EndIf
|
|||
|
||||
CloseDatabase(0)
|
||||
; IDE Options = PureBasic 6.12 LTS (Linux - x64)
|
||||
; CursorPosition = 63
|
||||
; FirstLine = 43
|
||||
; CursorPosition = 126
|
||||
; FirstLine = 89
|
||||
; Folding = -
|
||||
; EnableXP
|
||||
; DPIAware
|
Loading…
Add table
Add a link
Reference in a new issue