Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 01/13/2018 in all areas

  1. Added JsonDump() and updated/attached a new Zipfile in first post Jos
    2 points
  2. Earthshine

    Need Help

    I want to send him the hole code
    2 points
  3. Introduction JSON (Javascript Object Notation) is a popular data-interchange format and supported by a lot of script languages. On AutoIt, there is already a >JSON UDF written by Gabriel Boehme. It is good but too slow, and not supports unicode and control characters very well. So I write a new one (and of course, fast one as usual). I use a machine code version of JSON parser called "jsmn". jsmn not only supports standard JSON, but also accepts some non-strict JSON string. See below for example. Important Update!! I rename the library from jsmn.au3 to json.au3. All function names are changed, too. Decoding Function Json_Decode($Json) $Json can be a standard or non-standard JSON string. For example, it accepts: { server: example.com port: 80 message: "this looks like a config file" } The most JSON data type will be decoded into corresponding AutoIt variable, including 1D array, string, number, true, false, and null. JSON object will be decoded into "Windows Scripting Dictionary Object" retuned from ObjCreate("Scripting.Dictionary"). AutoIt build-in functions like IsArray, IsBool, etc. can be used to check the returned data type. But for Object and Null, Json_IsObject() and Json_IsNull() should be used. If the input JSON string is invalid, @Error will be set to $JSMN_ERROR_INVAL. And if the input JSON string is not finish (maybe read from stream?), @Error will be set to $JSMN_ERROR_PART. Encoding Function Json_Encode($Data, $Option = 0, $Indent = "\t", $ArraySep = ",\r\n", $ObjectSep = ",\r\n", $ColonSep = ": ") $Data can be a string, number, bool, keyword(default or null), 1D arrry, or "Scripting.Dictionary" COM object. Ptr will be converted to number, Binary will be converted to string in UTF8 encoding. Other unsupported types like 2D array, dllstruct or object will be encoded into null. $Option is bitmask consisting following constant: $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) $JSON_UNESCAPED_UNICODE ; Encode multibyte Unicode characters literally $JSON_UNESCAPED_SLASHES ; Don't escape / $JSON_HEX_TAG ; All < and > are converted to \u003C and \u003E $JSON_HEX_AMP ; All &amp;amp;amp;amp;s are converted to \u0026 $JSON_HEX_APOS ; All ' are converted to \u0027 $JSON_HEX_QUOT ; All " are converted to \u0022 $JSON_PRETTY_PRINT ; Use whitespace in returned data to format it $JSON_STRICT_PRINT ; Make sure returned JSON string is RFC4627 compliant $JSON_UNQUOTED_STRING ; Output unquoted string if possible (conflicting with $JSMN_STRICT_PRINT) Most encoding option have the same means like PHP's json_enocde() function. When $JSON_PRETTY_PRINT is set, output format can be change by other 4 parameters ($Indent, $ArraySep, $ObjectSep, and $ColonSep). Because these 4 output format parameters will be checked inside Jsmn_Encode() function, returned string will be always accepted by Jsmn_Decode(). $JSON_UNQUOTED_STRING can be used to output unquoted string that also accetped by Jsmn_Decode(). $JSON_STRICT_PRINT is used to check output format setting and avoid non-standard JSON output. So this option is conflicting with $JSON_UNQUOTED_STRING. Get and Put Functions Json_Put(ByRef $Var, $Notation, $Data, $CheckExists = False) Json_Get(ByRef $Var, $Notation) These functions helps user to access object or array more easily. Both dot notation and square bracket notation can be supported. Json_Put() by default will create non-exists objects and arrays. For example: Local $Obj Json_Put($Obj, ".foo", "foo") Json_Put($Obj, ".bar[0]", "bar") Json_Put($Obj, ".test[1].foo.bar[2].foo.bar", "Test") Local $Test = Json_Get($Obj, '["test"][1]["foo"]["bar"][2]["foo"]["bar"]') ; "Test" Object Help Functions Json_ObjCreate() Json_ObjPut(ByRef $Object, $Key, $Value) Json_ObjGet(ByRef $Object, $Key) Json_ObjDelete(ByRef $Object, $Key) Json_ObjExists(ByRef $Object, $Key) Json_ObjGetCount(ByRef $Object) Json_ObjGetKeys(ByRef $Object) Json_ObjClear(ByRef $Object) These functions are just warps of "Scripting.Dictionary" COM object. You can use these functions if you are not already familiar with it. == Update 2013/05/19 == * Add Jsmn_Encode() option "$JSMN_UNESCAPED_ASCII". Now the default output of Json_Encode() is exactly the same as PHP's json_encode() function (for example, chr(1) will be encoded into u0001). $JSON_UNESCAPED_ASCII ; Don't escape ascii charcters between chr(1) ~ chr(0x1f) == Update 2015/01/08 == * Rename the library from jsmn.au3 to json.au3. All function names are changed, too. * Add Json_Put() and Json_Get() * Add Null support * Using BinaryCall.au3 to loading the machine code. == Update 2018/01/13== (Jos) * Add JsonDump() to list all Json Keys and their values to easily figure out what they are. == Update 2018/10/01== (Jos) * Fixed JsonDump() some fields and values were not showing as discussed here - tnx @TheXman . == Update 2018/10/01b== (Jos) * Added Json_ObjGetItems, Tidied source and fixed au3check warnings - tnx @TheXman . == Update 2018/10/28== (Jos) * Added declaration for $value to avoid au3check warning - tnx @DerPensionist == Update 2018/12/16== (Jos) * Added another declaration for $value to avoid au3check warning and updated the version at the top - tnx @maniootek == Update 2018/12/29== (Jos) * Changed Json_ObjGet() and Json_ObjExists() to allow for multilevel object in string. == Update 2019/01/17== (Jos) * Added support for DOT notation in JSON functions. == Update 2019/07/15== (Jos) * Added support for reading keys with a dot inside when using a dot as separator (updated) == Update 2021/11/18== (TheXman) * Update details in below post: == Update 2021/11/20== (TheXman) * Minor RegEx update, no change to the functionality or result._Json(2021.11.20).zip
    1 point
  4. milos83

    Gui rounded rectangle hole

    @spudw2k Thank you! I have learned from your example! @jchd Now, searching for 'rounded rectangle hole' produces actual results!
    1 point
  5. When you play and experiment with the examples, for instance the example i posted, you can understand how it works, the explanation that exists, i think is the best one you'll get. Good luck.
    1 point
  6. Jos

    Get data from json

    Updated the original UDF post in Examples too and added the JsonDump() to the latest version. Jos
    1 point
  7. Jos

    Get data from json

    You are welcome Jos ps, could you please refrain quoting the whole post each time as it makes it much harder to read for everybody.
    1 point
  8. Jos

    Get data from json

    One other update to fix an bug in case the JSON data starts with an Array: $debug = 0 #include <Inet.au3> #include <json.au3> $data = FileRead("demo_json4.htm") Global $ObjLevel = -1 ;~ Global $ObjPath = "" Global $object = Json_Decode($data) Json_Dump($data) ;[0].id Func Json_Dump($Json, $InitTokenCount = 1000) Static $Jsmn_Init = __Jsmn_RuntimeLoader("jsmn_init"), $Jsmn_Parse = __Jsmn_RuntimeLoader("jsmn_parse") If $Json = "" Then $Json = '""' Local $TokenList, $Ret Local $Parser = DllStructCreate("uint pos;int toknext;int toksuper") Do DllCallAddress("none:cdecl", $Jsmn_Init, "ptr", DllStructGetPtr($Parser)) $TokenList = DllStructCreate("byte[" & ($InitTokenCount * 20) & "]") $Ret = DllCallAddress("int:cdecl", $Jsmn_Parse, "ptr", DllStructGetPtr($Parser), "wstr", $Json, "ptr", DllStructGetPtr($TokenList), "uint", $InitTokenCount) $InitTokenCount *= 2 Until $Ret[0] <> $JSMN_ERROR_NOMEM Local $Next = 0 _Json_TokenDump($Json, DllStructGetPtr($TokenList), $Next) EndFunc ;==>Json_Dump Func _Json_TokenDump(ByRef $Json, $Ptr, ByRef $Next, $ObjPath = "") If $Next = -1 Then Return Null Local $Token = DllStructCreate("int;int;int;int", $Ptr + ($Next * 20)) Local $Type = DllStructGetData($Token, 1) Local $Start = DllStructGetData($Token, 2) Local $End = DllStructGetData($Token, 3) Local $Size = DllStructGetData($Token, 4) $Next += 1 If $Type = 0 And $Start = 0 And $End = 0 And $Size = 0 Then ; Null Item $Next = -1 Return Null EndIf Switch $Type Case 0 ; Json_PRIMITIVE Local $Primitive = StringMid($Json, $Start + 1, $End - $Start) Switch $Primitive Case "true" Return True Case "false" Return False Case "null" Return Null Case Else If StringRegExp($Primitive, "^[+\-0-9]") Then Return Number($Primitive) Else Return Json_StringDecode($Primitive) EndIf EndSwitch Case 1 ; Json_OBJECT $ObjLevel += 1 If $debug Then ConsoleWrite('###>- Start objectlevel=' & $ObjLevel & " $Next=" & $Next & " $ObjPath:" & $ObjPath & " Size:" & $Size & @CRLF) ;### Debug Console For $i = 0 To $Size - 1 Step 2 Local $Key = _Json_TokenDump($Json, $Ptr, $Next) $cObjPath = $ObjPath & "." & $Key If $debug Then ConsoleWrite('+>- Start objectlevel=' & $ObjLevel & " $Next=" & $Next & " $cObjPath:" & $cObjPath & " Size:" & $Size & @CRLF) ;### Debug Console Local $Value = _Json_TokenDump($Json, $Ptr, $Next, $ObjPath & "." & $Key) If $debug Then ConsoleWrite('-<- Return objectlevel=' & $ObjLevel & " $Next=" & $Next & " $cObjPath:" & $ObjPath & " Size:" & $Size & @CRLF) ;### Debug Console If Not ($Value = False) Then If Not IsString($Key) Then $Key = Json_Encode($Key) EndIf If $ObjLevel <= 0 Then $CurJSONKey = "." & $Key EndIf ; show the key and its value ConsoleWrite("+-> " & $cObjPath & ' =' & $Value & @CRLF) If json_get($object, $cObjPath) <> $Value Then ConsoleWrite("! Error JSONGET() different! " & $cObjPath & '=' & $Value & ' JSONGET("' & $cObjPath & '")=' & json_get($object, $cObjPath) & @CRLF) EndIf EndIf Next If $debug Then ConsoleWrite('###< End object ' & $Next & @CRLF) ;### Debug Console $ObjLevel -= 1 Return False Case 2 ; Json_ARRAY Local $sObjPath = $ObjPath If $debug Then ConsoleWrite('$$$> Start Json_ARRAY:' & $ObjPath & " Size:" & $Size & @CRLF) ;### Debug Console Local $Array[$Size] For $i = 0 To $Size - 1 $sObjPath = $ObjPath & "[" & $i & "]" If $debug Then ConsoleWrite('$$$> TokenDump _ARRAY:' & $sObjPath & " Size:" & $Size & @CRLF) ;### Debug Console $Value = _Json_TokenDump($Json, $Ptr, $Next, $sObjPath) If $Value <> False Then ; show the key and its value ConsoleWrite("+=> " & $sObjPath & "=>" & $Value & @CRLF) EndIf Next If $debug Then ConsoleWrite('$$$< End Json_ARRAY:' & $ObjPath & @CRLF) ;### Debug Console $ObjPath = $sObjPath Return False Case 3 ; Json_STRING Local $LastKey = Json_StringDecode(StringMid($Json, $Start + 1, $End - $Start)) If $debug Then ConsoleWrite("=>" & $ObjPath & "." & $LastKey & ' (JSON STRING)' & @CRLF) Return $LastKey EndSwitch EndFunc ;==>_Json_TokenDump Jos
    1 point
  9. Come on ... think, it isn't that hard!! Of course the reverse of what you want is happening. PixelSearch() sets @error to 1 when it is unsuccessful and your loop ends. Jos
    1 point
  10. Yes, the loop is ending when @error is not equal to 0.
    1 point
  11. Jos

    Get data from json

    The error means I made an mistake in the logic. There is a check build in to verify the found path and its value, so when that error is shown it means there is something wrong.... which is clearly the case here. Updated the logic and seems to be better (and simpler). see here Just give it a try and let me know if it now runs without that error. Jos
    1 point
  12. Jos

    Need Help

    Hole or Whole?
    1 point
  13. mikell

    Help StringRegExp

    So what about _StringBetween ?
    1 point
  14. farouk12

    Help StringRegExp

    You want string between <ul> and </ul> ? if so. Stringregexp($String,"(?s)<ul>.*?\n(.*?)<\/ul>",3)
    1 point
  15. Gianni

    WinExists Issue

    ...hmm, yes, you are right, as you say I see that the button causing the deadlock is the one previously used to open the popup shown here and not the one in this snippet. Well, then the run command shown in my post above should be used against that previous button (adjusting accordingly the parameters) instead of on this one, and I think it will (should) work... P.S. @jdelaney I remember I had a problem similar to this one, and by searching on the forum I found the post where you already saved my ass once on a similar issue... thanks again..
    1 point
  16. Hi @tempman. Use HEAD method with a request to just get the header info and not the data. It's just the faster way. $oHTTP = ObjCreate("WinHttp.WinHttpRequest.5.1") $oHTTP.open("HEAD", "https://www.autoitscript.com/cgi-bin/getfile.pl?autoit3/autoit-v3-setup.exe", False) $oHTTP.send() Exit MsgBox(0, "", $oHTTP.Status<>200?'File does not exist':'File exists') I know URLs can result in other things than 200 and still be valid, but this will work for most cases.
    1 point
  17. Jos

    Get data from json

    Ok... understood. Try out this Json.Dump() UDF to see whether that is helpful to determine the proper Json path. Simply feed it with the JSON string : Json_Dump($data) and run it with SciTE. It will dump the JSON in the SciTEOutput pane. Jos see here
    1 point
  18. I tweaked the the _GuiHole function in the _WinAPI_CreateRoundRectRgn example in the help file to produce this result. #include <winapi.au3> #include <WinAPIGdi.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $hGUI = GUICreate("Test", 500, 500) GUISetBkColor(0x0000) WinSetTrans($hGUI,"",100) _GuiHole($hGUI, 50, 50, 80, 30, 8, 8) GUISetState() While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then Exit Wend Func _GuiHole($hWin, $iX, $iY, $iSizeW, $iSizeH, $iWidthEllipse, $iHeightEllipse) Local $hOuter_rgn, $hInner_rgn, $hCombined_rgn, $aPos = WinGetPos($hWin) $hOuter_rgn = _WinAPI_CreateRectRgn(0, 0, $aPos[2], $aPos[3]) $hInner_rgn = _WinAPI_CreateRoundRectRgn($iX, $iY, $iX + $iSizeW, $iY + $iSizeH, $iWidthEllipse, $iHeightEllipse) $hCombined_rgn = _WinAPI_CreateRoundRectRgn(0, 0, 0, 0, 0 ,0) _WinAPI_CombineRgn($hCombined_rgn, $hOuter_rgn, $hInner_rgn, $RGN_DIFF) _WinAPI_DeleteObject($hOuter_rgn) _WinAPI_DeleteObject($hInner_rgn) _WinAPI_SetWindowRgn($hWin, $hCombined_rgn) EndFunc ;==>_GuiHole
    1 point
  19. The largest SQLite DB I've had to do work with was greater than 120 Tb years ago and was hit 24/7 by hundreds of users. OK, it ran on fine tuned not-so-special hardware server (yet with loads of RAM) with very fined-tuned SQLite code, and I do mean very, very optimized code. But the competitive "solution" by Oracle was 25 times more expensive with inferior results. Remember that your GPS is most probably using a GIS system sit on an SQLite DB. Realize how many polygons of all kinds such a DB must hold to represent your country roads, plus all extra information. In your simple use case (5M rows is a baby DB), all you have to do is carefully plan your DB layout according to your actual needs and think twice about the queries you'll find most useful next year. You may want to create an FTS5 virtual table to lookup partial titles or words from titles for instance, support Unicode search for foreign characters, a.s.o. Deduce from SQLite "EXPLAIN QUERY PLAN ..." which index will help your actual queries, but don't rely on what you believe will help. I recommend you use a good SQLite DB manager (e.g. SQLite Expert) to start playing with a simple design and adjust it to satisfy your needs. Don't rush coding anything in AutoIt first, do this last. If you need guidance for a skeleton setup, just ask.
    1 point
×
×
  • Create New...