'-------------------------------------------------------
' NAME: JSON.bas
' Version: 1.0
' DATE: 2018-11-24
'-------------------------------------------------------
' DEVELOPMENT ENVIRONMENT
' OpSys: Windows
' Language: HotBasic
' Editor: AIRSyS-IDE
' Libraries: libparson.dll
'-------------------------------------------------------
' AUTHOR: Armando I. Rivera (AIR)
'-------------------------------------------------------
' DESCRIPTION:
' libparson Json parser interface
'
'-------------------------------------------------------
' Terms of Use/Licence
' MIT
'-------------------------------------------------------
declare sub JSONinit (filename as string)
declare function JSONtext(json_object as long,query as string) as string
declare function JSONobject(index as long) as long
OBJECT JSON
root as long
items as long
count as long
type as long
text as Function
object as function
init as Sub
END OBJECT
' JSON VALUE TYPE CODES
CONST JSONError = -1
CONST JSONNull = 1
CONST JSONString = 2
CONST JSONNumber = 3
CONST JSONObject = 4
CONST JSONArray = 5
CONST JSONBoolean = 6
begin runonce
cdecl function json_parse_file lib "libparson.dll" (filename as string) as long
cdecl function json_parse_string lib "libparson.dll" (strBuffer as string) as long
cdecl function json_value_get_type lib "libparson.dll" (json_object as long) as long
cdecl function json_value_get_array lib "libparson.dll" (json_object as long) as long
cdecl function json_array_get_count lib "libparson.dll" (json_object as long) as long
cdecl function json_object_get_string lib "libparson.dll" (json_object as long, keyname as string) as string
cdecl function json_object_dotget_string lib "libparson.dll" (json_object as long, keypath as string) as string
cdecl function json_array_get_object lib "libparson.dll" (json_object as long, index as long) as long
cdecl function json_object_dotget_value lib "libparson.dll" (json_object as long, keypath as string) as long
cdecl function json_object_get_value lib "libparson.dll" (json_object as long, keypath as string) as long
end runonce
Sub JSONinit(filename as string)
self.root = json_parse_file(filename)
self.type = json_value_get_type(self.root)
if self.type = JSONArray then
self.items = json_value_get_array(self.root)
self.count = json_array_get_count(self.items)
end if
End Sub
function JSONtext(json_object as long, query as string) as string
defstr res
if instr(query, ".") then
if json_object_dotget_value(json_object,query) <> 0 then
res = json_object_dotget_string(json_object, query)
end if
' print res
else
if json_object_get_value(json_object,query) <> 0 then
res = json_object_get_string(json_object, query)
end if
end if
result = res
end function
function JSONobject(index as long) as long
result = json_array_get_object(self.items, index)
end function