save point
This commit is contained in:
parent
9cb5c91e7e
commit
08f9208e02
2 changed files with 97 additions and 0 deletions
BIN
json.db
BIN
json.db
Binary file not shown.
97
jsonlib2.pb
Normal file
97
jsonlib2.pb
Normal file
|
@ -0,0 +1,97 @@
|
|||
UseSQLiteDatabase()
|
||||
|
||||
Procedure searchkey()
|
||||
searchKey$ = "your.key.path"
|
||||
query$ = "SELECT * FROM json_data WHERE key = '" + searchKey$ + "'"
|
||||
|
||||
If DatabaseQuery(0, query$)
|
||||
While NextDatabaseRow(0)
|
||||
Debug "Key: " + GetDatabaseString(0, 0)
|
||||
Debug "Parent Key: " + GetDatabaseString(0, 1)
|
||||
Debug "Type: " + GetDatabaseString(0, 2)
|
||||
Debug "Value: " + GetDatabaseString(0, 3)
|
||||
Wend
|
||||
FinishDatabaseQuery(0)
|
||||
Else
|
||||
Debug "Error executing query: " + DatabaseError()
|
||||
EndIf
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure searchval()
|
||||
searchValue$ = "specific value"
|
||||
query$ = "SELECT * FROM json_data WHERE value = '" + searchValue$ + "'"
|
||||
|
||||
If DatabaseQuery(0, query$)
|
||||
While NextDatabaseRow(0)
|
||||
Debug "Key: " + GetDatabaseString(0, 0)
|
||||
Debug "Parent Key: " + GetDatabaseString(0, 1)
|
||||
Debug "Type: " + GetDatabaseString(0, 2)
|
||||
Debug "Value: " + GetDatabaseString(0, 3)
|
||||
Wend
|
||||
FinishDatabaseQuery(0)
|
||||
Else
|
||||
Debug "Error executing query: " + DatabaseError()
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
|
||||
Procedure ProcessJSONObject(ObjectValue, parentKey$)
|
||||
If ExamineJSONMembers(ObjectValue)
|
||||
While NextJSONMember(ObjectValue)
|
||||
key$ = JSONMemberKey(ObjectValue)
|
||||
MemberValue = JSONMemberValue(ObjectValue)
|
||||
fullKey$ = parentKey$ + key$
|
||||
|
||||
Select JSONType(MemberValue)
|
||||
Case #PB_JSON_String
|
||||
value$ = GetJSONString(MemberValue)
|
||||
type$ = "String"
|
||||
|
||||
Case #PB_JSON_Number
|
||||
value$ = StrD(GetJSONDouble(MemberValue))
|
||||
type$ = "Number"
|
||||
|
||||
Case #PB_JSON_Boolean
|
||||
value$ = Str(Bool(GetJSONBoolean(MemberValue)))
|
||||
type$ = "Boolean"
|
||||
|
||||
Case #PB_JSON_Object
|
||||
value$ = "(nested object)"
|
||||
type$ = "Object"
|
||||
; Recursively process the nested object
|
||||
ProcessJSONObject(MemberValue, fullKey$ + ".")
|
||||
|
||||
Case #PB_JSON_Array
|
||||
value$ = "(nested array)"
|
||||
type$ = "Array"
|
||||
; Handle array values if needed.
|
||||
|
||||
Default
|
||||
value$ = "(unknown type)"
|
||||
type$ = "Unknown"
|
||||
|
||||
EndSelect
|
||||
|
||||
; Insert the parsed data into the SQLite database
|
||||
query$ = "INSERT INTO json_data (key, parent_key, type, value) VALUES ('" + fullKey$ + "', '" + parentKey$ + "', '" + type$ + "', '" + value$ + "')"
|
||||
If DatabaseUpdate(0, query$) = 0
|
||||
Debug "Error inserting data: " + DatabaseError()
|
||||
EndIf
|
||||
Wend
|
||||
EndIf
|
||||
EndProcedure
|
||||
|
||||
OpenDatabase(0, "json.db", "", "", #PB_Database_SQLite)
|
||||
|
||||
LoadJSON(1, "results.json")
|
||||
ParseJSON(1, json$) ; returns garbage without the PB ascii there not sure why
|
||||
ObjectValue = JSONValue(1)
|
||||
|
||||
ProcessJSONObject(ObjectValue, "")
|
||||
; IDE Options = PureBasic 6.12 LTS (Linux - x64)
|
||||
; CursorPosition = 37
|
||||
; FirstLine = 11
|
||||
; Folding = -
|
||||
; EnableXP
|
||||
; DPIAware
|
Loading…
Add table
Add a link
Reference in a new issue