I have this as a result from a download on Joplin. (jsonResult)
{"items":[{"id":"f4bfd5334d074a8ab5e414213561e1ea","parent_id":"1462c63203244ab88f5e729673ae87d1","title":"Core Zettel idee","deleted_time":0},{"id":"30e176160896445eacfdd0305e4d2f0a","parent_id":"1462c63203244ab88f5e729673ae87d1","title":"Map of content","deleted_time":0}],"has_more":true}
I looks like JSON but I don't get it, how to read it with PureBasic.
Been messing with the code examples in the help files.
But it's none of the values. Object, Array, ..
I got it as a Object by parsing but then how to get values from an jsonObject.
How do I get an understanding of this JSON handling?
Many thanks
Rudi
Code: Select all
Procedure GetJoplinNotes()
; Gebruik het gevalideerde endpoint voor notes
url.s = "http://localhost:41184/notes?token=" + API_Token
HttpRequest = HTTPRequest(#PB_HTTP_Get, url, "", #PB_HTTP_Asynchronous)
If HttpRequest
Repeat
Progress = HTTPProgress(HttpRequest)
Select Progress
Case #PB_HTTP_Success
Debug "Download voltooid"
*Buffer = HTTPMemory(HttpRequest)
If *Buffer
; Converteer buffer naar UTF-8 string
jsonResult.s = PeekS(*Buffer, MemorySize(*Buffer),#PB_UTF8)
; Debuggen van ontvangen JSON
; Debug "Ontvangen JSON lengte: " + Str(Len(jsonResult)) + Chr(10)
Debug "Eerste 1000 tekens: " + Left(jsonResult, 1000) + Chr(10)
Debug jsonResult
; jsType.s=GetAnyValue(jsonRoot); number expected!!!!
; Debug "json objectValue type = " + jsType ; = null dus hier is het geen JSON!!!
;GetAnyValue(jsonResult) must be a number
; JSON maken
If CreateJSON(#json)
jsonRoot = SetJSONArray(JSONValue(0))
SetJSONString(AddJSONElement(jsonRoot), jsonResult);"with escaped new" + Chr(13) + Chr(10) + "line")
;SetJSONString(AddJSONElement(jsonResult), "with escaped \ backslash")
;Debug jsonRoot
Debug ComposeJSON(#json,#PB_JSON_PrettyPrint)
GetAnyValue(jsonRoot)
EndIf
; Debug jsonRoot
; Debug JSONObjectSize(jsonRoot)
;jsonObject.i = ParseJSON(10, jsonRoot)
;Debug JSONArraySize(JSONValue(0))
;jsType=GetAnyValue(ComposeJSON(0))
;Debug "json jsonRoot type = " + jsType ;
; For i = 0 To JSONArraySize(JSONValue(0)) - 1
; Debug GetJSONInteger(GetJSONElement(JSONValue(0), i))
; Next i
; Debug "Json Type: " + JSONType(jsonResult)
; DIT IS INGEVOEGD
;
; If ExamineJSONMembers(JSONValue(0))
; Debug "displaying JSON object members with string values only:"
; ; iterate through the members of the json object
; While NextJSONMember(0)
;
; ;display only members With values of string types
; If JSONType(JSONMemberValue(0)) = #PB_JSON_String
;
; Debug "> " + JSONMemberKey(JSONValue(0)) + " = " +
; GetJSONString(JSONMemberValue(0))
;
; EndIf
; Wend
; EndIf
;
; TOT HIER INGEVOEGD
FreeMemory(*Buffer)
EndIf
FinishHTTP(HttpRequest)
Break
Case #PB_HTTP_Failed
Debug "Download mislukt"
FinishHTTP(HttpRequest)
Break
EndSelect
Delay(100)
ForEver
Else
Debug "Aanmaken request mislukt"
EndIf
EndProcedure




