Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 02/01/2023 in all areas

  1. Introduction JSON is a pure data exchange format. Basically you only have to deal with JSON in 2 places in a program: Once when reading JSON data and once when outputting data. In between it should not really matter that the data used to be JSON or should be converted to it. You should not need any special intermediate structures but only the elements that the respective programming language provides anyway. This is exactly the approach of this UDF: There is the function _JSON_Parse(), which converts an arbitrary JSON string into (nested) pure AutoIt data types (Arrays, Maps, Strings, Numbers, Null, True, False). And on the other side we have the function _JSON_Generate(), which generates a JSON string from arbitrary (nested) AutoIt data structures. Import and export JSON So how to use - let`s give an example: Handling nested data structures JSON is often very nested. The resulting AutoIt data is therefore naturally also nested, which makes it somewhat cumbersome to process with pure AutoIt on-board methods. For this reason, the UDF comes with a few helper functions that make life with this data easier. One of them is _JSON_Get(), which allows you to access deeply nested data with a simple query syntax. On the other hand there is the function _JSON_addChangeDelete() with which you can (the name already says it) change, add and delete data. You can even easily create deeply nested structures with a single call. Again, here is a small example of how to use it: Strictly speaking, these functions should not even have "JSON" in their names, since they are generally applied to data structures in AutoIt. However, since they are often used in the JSON environment, we allow ourselves this small inaccuracy. Why should i give it a try? Probably the most common method to deal with JSON in AutoIt is the variant via JSMN. My minor dissatisfactions with this approach led me to write this UDF in the first place a few years ago. So the incentives are quite JSMN related: Parsing and extraction of data is faster than in JSMN. (Only if the JSON string makes heavy use of JSON escapes should JSMN be a bit faster in parsing, since the escapes are resolved later.) Editing the data is easier, because you don't need special commands for the JSMN intermediate structure but deal directly with AutoIt structures. Generating JSON is also simple: build your structure in AutoIt as you like and then let it generate a JSON string for you with _JSON_Generate(). The UDF is smaller (28kb vs. 45kb) The UDF is in pure AutoIt. You can directly customize any behavior as you like. >>sourcecode and download on github<<
    2 points
  2. Is there any particular reason why you absolutely need to convert this to an array in between? You can edit the data directly without wildly converting: Otherwise you would first have to convert the map array into a 2D array, then make your changes there and then convert the 2D array into a map array again. This is feasible and I have also a function for the reverse direction, but for me it seems artificially cumbersome: I'm not a native speaker either - your English sounds sufficiently good to me.
    1 point
  3. You would have to describe in more detail what you mean by array, because behind the attribute "people" there is already an array - more precisely an array of maps. You would have to describe the exact shape if you want something else. If you want to have a 2D array from the map array, then you have to do yourself: Edit: For such special cases as creating a 2D array from an array-of-maps, you can also write yourself a reusable function. Curiously, I have written such a function for exactly this case (from a not yet published UDF):
    1 point
  4. a bit experimental $aMouse_Pos = MouseGetPos() ; Keep ToolTip on screen If $aMouse_Pos[0] > (@DesktopWidth - 250) Then $iX = $aMouse_Pos[0] - 250 Else $iX = $aMouse_Pos[0] + 20 EndIf If $aMouse_Pos[1] > (@DesktopHeight - 100) Then $iY = $aMouse_Pos[1] - 100 Else $iY = $aMouse_Pos[1] + 20 EndIf ToolTip($ToolTipText, $iX, $iY, "info", 1)
    1 point
  5. @Danp2 That is a pretty neat thread and approach to doing things, thanks for linking it, I may not have seen it otherwise. Another option for @SkysLastChance would also be to get the AutoIt3.exe (or AutoIt3_x64.exe) itself approved, and then you could use a .bat or shortcut to call an uncompiled script or compiled as .a3x. .bat file would look something like: "C:\Program Files (x86)\AutoIt3\AutoIt3_x64.exe" "C:\Users\User\Documents\AutoIt\DoSomething.a3x" Though I doubt that IT would approve the AutoIt exe itself... That Au3toCmd really seems like a good option. Also if you're able to get the AutoIt exe approved or AutoIt installed, you don't even need to compile as .a3x, the .au3 file will work using the same syntax with a .bat file or a shortcut in the startup folder. https://www.autoitscript.com/autoit3/docs/intro/running.htm
    1 point
  6. You could use Au3toCmd. Otherwise, you would need to distribute Autoit3.exe with your .au3 file and place a shortcut in the user's startup folder.
    1 point
  7. To be fair, I have attached a file where the ratio is the other way around. The reason here is that there is massive use of JSON unicode char escapes in the file. The escapes resolution seems to be implemented more efficiently in jsmn. To be honest it is still a big mystery to me how a parser written in pure AutoIt and executed by interpreter can be faster (even if it were only in a few cases) than one in machine code. On the other hand, it must be said that jsmn does not peddle great speed, but rather the small code size and the portability of the code. These promises are simply kept by jsmn. Aerosmith.json
    1 point
  8. ioa747

    JSON UDF in pure AutoIt

    Congratulations !! file size JSMN Pure AutoIt ;~ ------------------------------------------------------------------------ ;~ sample4.json 451 bytes 2.64 ms 0.77 ms ;~ test.json 1,46 KB 3.93 ms 2.48 ms ;~ USD.json 2,12 KB 10.68 ms 6.42 ms ;~ 110-pcp-ytd-12-1895-2016.json 5,43 KB 54.20 ms 13.42 ms ;~ earth_meteorites.json 240 KB 1339.18 ms 546.57 ms ;~ Test2.json 2,04 MB 4180.48 ms 2172.16 ms
    1 point
  9. Found it finally. Much much cleaner. I post the solution in case of someone could need it Too bad the $ES_NOOLEDRAGDROP constant was not documented #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> ;#Include <Array.au3> #include <GuiEdit.au3> #include <GuiRichEdit.au3> #include <WinAPISys.au3> Global Const $ES_NOOLEDRAGDROP = 0x08 Global Const $tagDROPFILES = $tagNMHDR & ";handle hDrop;long cp;bool fProtected" $gui = GUICreate("test", 600, 400, -1, 100, -1, $WS_EX_ACCEPTFILES) $edit = GUICtrlCreateEdit("", 10, 10, 580, 180, BitOr($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL) ) GUICtrlSetState(-1, $GUI_DROPACCEPTED) $hRichEdit = _GUICtrlRichEdit_Create($gui, "", 10, 200, 580, 180, BitOr($ES_NOOLEDRAGDROP, $ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL)) _GUICtrlRichEdit_SetLimitOnText($hRichEdit, 100000) GUISetState() _WinAPI_DragAcceptFiles ($hRichEdit) _GUICtrlRichEdit_SetEventMask($hRichEdit, $ENM_DROPFILES) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $GUI_EVENT_DROPPED $dropped = @GUI_DragFile If StringRight($dropped, 4) <> ".txt" Then ContinueLoop GuiCtrlSetData($edit, FileRead($dropped)) EndSwitch WEnd Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $iMsg, $wParam Local $hWndFrom, $iCode, $tNMHDR, $tDropFiles, $hDrop, $aFileList $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hRichEdit Select Case $iCode = $EN_DROPFILES $tDropFiles = DllStructCreate($tagDROPFILES, $lParam) $hDrop = DllStructGetData($tDropFiles, "hDrop") $aFileList = _WinAPI_DragQueryFileEx($hDrop, 1) ; files only If @error OR $aFileList[0] > 1 OR StringRight($aFileList[1], 4) <> ".txt" Then _ Return _GUICtrlRichEdit_SetText($hRichEdit, "") _NewFile($aFileList[1]) _WinAPI_DragFinish($hDrop) EndSelect EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _NewFile($newfile) $filetxt = FileRead($newfile) _GUICtrlRichEdit_SetText($hRichEdit, "") _GUICtrlRichEdit_AppendText($hRichEdit, $filetxt) _GUICtrlRichEdit_SetSel($hRichEdit, 0, 0) EndFunc
    1 point
  10. How do I send a Button Click with GUICtrlSendMsg() to myself? Thanks! Chris
    0 points
×
×
  • Create New...